JavaMethods That AffectMATLABCommands
MATLAB®commands that operate on Java®objects and arrays use the methods that are implemented within, or inherited by, the class. There are some MATLAB commands that you can alter in behavior by changing the Java methods that they use.
Changing the Effect ofdisp
anddisplay
You call thedisp
function when you:
Display the value of a variable or an expression in MATLAB.
Terminate a command line without a semicolon.
Display a Java object in MATLAB.
When callingdisp
on a Java object, MATLAB formats the output using the objecttoString
method. If the class does not implement this method, then MATLAB uses an inheritedtoString
method. If no intermediate ancestor classes define this method, MATLAB uses thetoString
method defined by thejava.lang.Object
class.
To change the way MATLAB displays an object, implement your owntoString
method in your class definition.
Changing the Effect ofisequal
The MATLABisequal
function compares two or more arrays for equality in type, size, and contents. Also, you can use this function to test Java objects for equality.
When you compare two Java objects usingisequal
, MATLAB performs the comparison using the Java method,equals
. MATLAB first determines the class of the objects specified in the command, and then uses theequals
method implemented by that class. Ifequals
is not implemented in this class, then MATLAB uses an inheritedequals
method. If no intermediate ancestor classes define this method, MATLAB uses theequals
method defined by thejava.lang.Object
class.
To change the way MATLAB compares members of a class, implement your ownequals
method in your class definition.
Changing the Effect ofdouble
,string
, andchar
You can change the output of the MATLABdouble
,string
, andchar
functions by defining your own Java methods,toDouble
,toString
, andtoChar
. For more information, seeConvert to MATLAB Numeric TypesandConvert to MATLAB Strings.