External Interfaces |
Java Methods That Affect MATLAB Commands
MATLAB commands that operate on Java objects and arrays make use of the methods that are implemented within, or inherited by, these objects' classes. There are some MATLAB commands that you can alter somewhat in behavior by changing the Java methods that they rely on.
Changing the Effect of disp and display
You can use the disp
function to display the value of a variable or an expression in MATLAB. Terminating a command line without a semicolon also calls the disp
function. You can also use disp
to display a Java object in MATLAB.
When disp
operates on a Java object, MATLAB formats the output using the toString
method of the class to which the object belongs. If the class does not implement this method, then an inherited toString
method is used. If no intermediate ancestor classes define this method, it uses the toString
method defined by the java.lang.Object
class. You can override inherited toString
methods in classes that you create by implementing such a method within your class definition. In this way, you can change the way MATLAB displays information regarding the objects of the class.
Changing the Effect of isequal
The MATLAB isequal
function compares two or more arrays for equality in type, size, and contents. This function can also be used to test Java objects for equality.
When you compare two Java objects using isequal
, MATLAB performs the comparison using the Java method, equals
. MATLAB first determines the class of the objects specified in the command, and then uses the equals
method implemented by that class. If it is not implemented in this class, then an inherited equals
method is used. This will be the equals
method defined by the java.lang.Object
class if no intermediate ancestor classes define this method.
You can override inherited equals
methods in classes that you create by implementing such a method within your class definition. In this way, you can change the way MATLAB performs comparison of the members of this class.
Changing the Effect of double and char
You can also define your own Java methods toDouble
and toChar
to change the output of the MATLAB double
and char
functions. For more information, see the sections entitled Converting to the MATLAB double Data Type and Converting to the MATLAB char Data Type.
Obtaining Information About Methods | How MATLAB Handles Undefined Methods |
© 1994-2005 The MathWorks, Inc.