MATLAB Object-Oriented Programming

(Joyce) #1

  • MATLAB executes a statement that returns a value and is not terminated with a
    semicolon.

  • There is no left-side variable, then MATLAB prints ans = followed by the value.

  • Code explicitly invokes the display function.


When invoking display:



  • If the input argument is an existing variable, display prints the variable name and
    equal sign, followed by the value.

  • If the input is the result of an expression, display does not print ans =.


MATLAB invokes the built-in disp function when the following occurs:



  • The built-in display function calls disp.

  • Code explicitly invokes disp.


For empty built-in types (numeric types, char, struct, and cell) the display function
displays:



  • [] — for numeric types

  • "0x0 struct array with no fields." — for empty structs.

  • "0x0 empty cell array" — for empty cell arrays.

  • "0x0 empty char array" — for empty char arrays

  • "0x0 empty string array" — for empty string arrays


disp differs from display in these ways:



  • disp does not print the variable name or ans.

  • disp prints nothing for built-in types (numeric types, char, struct, and cell) when
    the value is empty.


See Also


Related Examples



  • “Custom Display Interface” on page 18-2

  • “Overload disp for DocPolynom” on page 19-17


See Also
Free download pdf