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.
disp
and display
You call the disp
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 calling disp
on a Java object, MATLAB formats
the output using the object toString
method. If
the class does not implement this method, then MATLAB uses an
inherited toString
method. If no intermediate ancestor
classes define this method, MATLAB uses the toString
method
defined by the java.lang.Object
class.
To change the way MATLAB displays an object, implement
your own toString
method in your class definition.
isequal
The MATLAB isequal
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 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 equals
is not implemented in this class,
then MATLAB uses an inherited equals
method.
If no intermediate ancestor classes define this method, MATLAB uses
the equals
method defined by the java.lang.Object
class.
To change the way MATLAB compares members of a class, implement
your own equals
method in your class definition.
double
, string
, and char
You can change the output of the MATLAB double
, string
,
and char
functions by defining your own Java methods, toDouble
, toString
,
and toChar
. For more information, see Convert to MATLAB Numeric Types and Convert to MATLAB Strings.