Show information about variable or result of expression
display( is called by MATLAB® when a statement or expression is not terminated by a semicolon. Omitting the terminating semicolon from a statement or expression displays a result.
MATLAB calls the
display function to show information about an intermediate result, such as the values, size, type, and variable name.
To show the value of a variable or to show program output in the command window, use the
To customize the display of user-defined objects, use the techniques described in the Customize Object Display for Classes topic.
Unterminated Variable Assignment
display when you make an assignment to a variable without terminating the statement with a semicolon. In this example,
display shows the variable name and the value.
a = 7
a = 7
Terminated Variable Assignment
MATLAB does not call
display when you make an assignment to a variable and the statement is terminated with a semicolon.
a = 7;
When you execute an expression without a semicolon, MATLAB assigns the result to a variable called
ans, which the
display function shows in the command window.
format long sqrt(2)
ans = 1.414213562373095
X — Result of executing a statement or expression
variable | expression
Result of executing a statement or expression, passed to the
display function by MATLAB.
Executing an expression without terminating the expression with a semicolon causes the result to be displayed in the command window. MATLAB assigns the result of an expression to a variable named
ans when the result is not assigned to a variable explicitly.
4 * 5 - 13
ans = 7
To display the result in the command window without displaying
ans, use the
disp(4 * 5 - 13)
If an expression is terminated by a semicolon, MATLAB does not display a value, but still assigns the result to the
4 * 5 - 13; ans
ans = 7
Display Results in Command Window
Omitting the terminating semicolon is useful when you want to see intermediate results from statements in a program. For example, compare these two statements by omitting the semicolon. The
display function shows the results in the command window.
result1 = 4 * 5 - 13
result1 = 7
result2 = 4 * (5 - 13)
result2 = -32
Information Shown by the
display function provides information about the kind of values that are the result of executing a statement or expression. This information is useful for understanding how a program or script works.
For example, this statement assigns a
uint8 vector of values
1 2 3 4 to the variable named
display function shows the variable name, the size and type, and the values.
a = uint8([1 2 3 4])
a = 1×4 uint8 row vector 1 2 3 4
For empty values (numeric types,
display function displays:
— for numeric types
"0x0 struct array with no fields."— for empty
"0x0 empty cell array"— for empty cell arrays.
"0x0 empty char array"— for empty
"0x0 empty string array"— for empty
To show the actual values that are the intended output from a program, like text and numbers, call the
disp function. The
disp function does not display the variable name or
disp displays nothing for built-in types (numeric types,
cell) when the value is empty.
Run code in the background using MATLAB®
backgroundPool or accelerate code with Parallel Computing Toolbox™
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.