23.12.2012 Views

MATLAB Function Reference Volume 1: A - E - Bad Request

MATLAB Function Reference Volume 1: A - E - Bad Request

MATLAB Function Reference Volume 1: A - E - Bad Request

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2display<br />

Purpose Overloaded method to display an object<br />

Syntax display(X)<br />

display<br />

Description display(X) prints the value of a variable or expression, X. <strong>MATLAB</strong> calls<br />

display(X) when it interprets a variable or expression, X, that is not<br />

terminated by a semicolon. For example, sin(A) calls display, while sin(A);<br />

does not.<br />

If X is an instance of a <strong>MATLAB</strong> class, then <strong>MATLAB</strong> calls the display method<br />

of that class, if such a method exists. If the class has no display method or if X<br />

is not an instance of a <strong>MATLAB</strong> class, then the <strong>MATLAB</strong> builtin display<br />

function is called.<br />

Examples A typical implementation of display calls disp to do most of the work and looks<br />

like this.<br />

function display(X)<br />

if isequal(get(0,'FormatSpacing'),'compact')<br />

disp([inputname(1) ' =']);<br />

disp(X)<br />

else<br />

disp(' ')<br />

disp([inputname(1) ' =']);<br />

disp(' ');<br />

disp(X)<br />

end<br />

The expression magic(3), with no terminating semicolon, calls this function as<br />

display(magic(3)).<br />

magic(3)<br />

ans =<br />

8 1 6<br />

3 5 7<br />

4 9 2<br />

As an example of a class display method, the function below implements the<br />

display method for objects of the <strong>MATLAB</strong> class, polynom.<br />

2-449

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!