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.

Note that disp does not display empty arrays.

Examples

Example 1 — Display a matrix with column labels

One use of disp in an M-file is to display a matrix with column labels:

disp('         Corn         Oats         Hay')
disp(rand(5,3))

which results in

         Corn         Oats         Hay
        0.2113        0.8474        0.2749
        0.0820        0.4524        0.8807
        0.7599        0.8075        0.6538
        0.0087        0.4832        0.4899
        0.8096        0.6135        0.7741

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">The MathWorks Web Site</a>')

which generates this hyperlink in the Command Window:

The 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 concatenation to display multiple items using disp. For example:

x = [1 2 3];
disp(['The values of x are: ', num2str(x)]);

displays

The values of x are: 1  2  3

If you want to display text without a trailing newline character, use fprintf. For example,

fprintf('%s %d %d %d ', 'The values of x are:', x(:));

displays text similar to the above, but does not include a newline.

See Also

format, int2str, matlabcolon, num2str, rats, sprintf, fprintf

  


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