| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
| On this page… |
|---|
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.
For examples of overloaded disp methods, see the following sections:
Displaying TensileData Objects
MATLAB invokes the built-in display function when:
MATLAB executes a statement that returns a value and is not terminated with a semicolon.
Code explicitly invokes the display function.
MATLAB invokes the built-in disp function in the following cases:
The built-in display function calls disp.
Code explicitly invokes disp.
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.
![]() | Defining Concatenation for Your Class | Converting Objects to Another Class | ![]() |

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 |