Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

Displaying Objects in the Command Window

Default Display

MATLAB software calls a method named display whenever an object is referred to in a statement that is not terminated by a semicolon. For example, the following statement creates the variable a and calls the MATLAB display method for class double. This method displays the value of a in the command line.

a = 5
a =
    5

All MATLAB objects use default disp and display functions. You do not need to overload the defaults, but you can overload in cases where you want objects to display in different ways.

You can define a disp method for your classes if you want MATLAB to display more useful information on the command line when referring to objects from your class. In many classes, disp can print the variable name, and then use the char converter method to print the contents of the variable. You need to define the char method to convert the object's data to a character string because MATLAB displays output as character strings.

You might also use sprintf or other data formatting functions to implement the disp method for your class.

Examples of disp Methods

For examples of overloaded disp methods, see the following sections:

Displaying TensileData Objects

The DocPolynom disp Method

The DocAsset Display Method

The DocPortfolio disp Method

Relationship Between disp and display

MATLAB invokes the built-in display function when:

MATLAB invokes the built-in disp function in the following cases:

Override disp Or disp and display

The built-in display function prints the name of the variable that is being displayed, if an assignment is made, or otherwise uses ans as the variable name. display then calls disp to handle the actual display of the values.

If the variable that is being displayed is an object of a class that overloads disp, then MATLAB always calls the overloaded method. Overload disp or disp and display to customize the display of objects. Overloading only display is not sufficient to properly implement a custom display for your class.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS