Actual and Displayed Results of Evaluations

MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

When MuPAD® evaluates an expression or executes a command, the output that the system displays can differ from the actual result. The simplest example of this behavior is that MuPAD does not display all computed results. You can suppress outputs by terminating commands with colons. For example, the evaluation of the following expression returns 4. However, MuPAD does not display any output because the expression is terminated with a colon:

2 + 2:

The function call last(1) returns the previously computed value. Alternatively, you can use the operator % to return that value:

%

MuPAD also suppresses intermediate results obtained within loops and procedures. For example, the evaluation of the following for loop returns five numbers. However, the output contains only the final result:

for x from 1 to 5 do
  hold(_power)(x, 2) = x^2
end_for

To display intermediate results obtained in loops and procedures, use the print function inside a loop or a procedure. For example, to display all five numbers obtained in the for loop, enter:

for x from 1 to 5 do
  print(hold(_power)(x, 2) = x^2)
end_for

Alternatively, use the fprint function. This function typically writes results to a file indicated by one of the arguments of fprint. When this argument is 0, the function displays the results on screen:

for x from 1 to 5 do
  fprint(Unquoted, 0, hold(_power)(x, 2) = x^2);
end_for
1^2 = 1
2^2 = 4
3^2 = 9
4^2 = 16
5^2 = 25

The print and fprint functions display outputs differently. The print function uses the typeset mode, which is how mathematical expressions are typically written on paper. The fprint function uses the ASCII format. For information about different output modes available in MuPAD, see Using Different Output Modes.