Skip to Main Content Skip to Search
Product Documentation

disp - Display text or array

Syntax

disp(X)

Description

disp(X) displays an array, without printing the array name. If X contains a text string, the string is displayed.

Another way to display an array on the screen is to type its name, but this prints a leading "X=," which is not always desirable.

The disp function accepts only one input. To display more than one array or string, you can use concatenation or the sprintf or fprintf functions as shown in Example 3 — Display multiple items on the same line.

Note that disp does not display empty arrays.

Examples

Example 1 — Display a matrix with column labels

This example uses disp to display a matrix with column labels:

disp('     Corn      Oats      Hay')
x = gallery('uniformdata',[5 3],0);
disp(x)

This results in

     Corn      Oats      Hay
    0.9501    0.7621    0.6154
    0.2311    0.4565    0.7919
    0.6068    0.0185    0.9218
    0.4860    0.8214    0.7382
    0.8913    0.4447    0.1763

Example 2 — Display a hyperlink in the Command Window

You also can use the disp command to display a hyperlink in the Command Window. Include the full hypertext string on a single line as input to disp:

disp('<a href = "http://www.mathworks.com">MathWorks Web Site</a>')

which generates this hyperlink in the Command Window:

MathWorks Web Site

Click the link to display the MathWorks home page in a MATLAB Web browser.

Example 3 — Display multiple items on the same line

Use any of the following techniques to display multiple items on the same line:

See Also

colon (:) | format | fprintf | int2str | num2str | rats | sprintf

  


» Learn more
» Download free kit
» Get trial software

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