Mouseover text to see original. Click the button below to return to the English version of the page.
Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.
Translate This Page
MathWorks Machine Translation
The automated translation of this page is provided by a general purpose third party translator tool.
MathWorks does not warrant, and disclaims all liability for, the accuracy, suitability, or fitness for purpose of the translation.
disp(X) displays the
value of variable X without printing the variable
name. Another way to display a variable is to type its name, which
displays a leading “X =” before the
value.
If a variable contains an empty array, disp returns
without displaying anything.
Here are three ways to display multiple variable values on the same line in the Command Window.
Concatenate multiple character vectors together using the [] operator. Convert any numeric values to characters using the num2str function. Use disp to display the result.
name = 'Alice';
age = 12;
X = [name,' will be ',num2str(age),' this year.'];
disp(X)
Alice will be 12 this year.
Use sprintf to create text, and then display it with disp.
name = 'Alice';
age = 12;
X = sprintf('%s will be %d this year.',name,age);
disp(X)
Alice will be 12 this year.
Use fprintf to directly display the text without creating a variable. However, to terminate the display properly, you must end the text with the newline (\n) metacharacter.
name = 'Alice';
age = 12;
fprintf('%s will be %d this year.\n',name,age);
To display more than one array, you can use concatenation or
the sprintf or fprintf functions
as shown in the example, Display Multiple Variables on Same Line.
You can also select a location from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.