Display Progress

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.

By default, MuPAD® procedures do not show progress information or comments on run time. For example, create the following procedure that returns the sign of an input number. (MuPAD provides the standard function sign for this task.)

S := proc(z:Type::Numeric)
begin
  if not(testtype(z, Dom::Real)) then
    z/abs(z)
  elif z > 0 then
    1
  elif z < 0 then
    -1
  else
    0
  end_if
end_proc:

When you execute this procedure, it returns only the final result:

S(10)

Typically, the final result is all that your users want to see. However, if executing a procedure takes a long time or if users can benefit from the comments on some procedure steps, you can extend the procedure to include additional information. To embed the progress information into your procedure, use the print function. For example, modify the procedure S so it reports its progress:

S := proc(z:Type::Numeric)
begin
  print(Unquoted, "Is ".expr2text(z)." a real number?");
  if not(testtype(z, Dom::Real)) then
    print(Unquoted, expr2text(z)." is a complex number. Computing...
                            the sign of ".expr2text(z)." as z/|z|");
    z/abs(z);
  else
    print(Unquoted, expr2text(z)." is a real number");
    print(Unquoted, "Is ".expr2text(z)." a positive number?");
    if z > 0 then
      print(Unquoted, expr2text(z)." is a positive number");
      1
    else
      print(Unquoted, expr2text(z)." is not a positive number");
      print(Unquoted, "Is ".expr2text(z)." a negative number?");
      if z < 0 then
        print(Unquoted, expr2text(z)." is a negative number");
        -1
      else
        print(Unquoted, expr2text(z)." is not a negative number");
        print(Unquoted, expr2text(z)." is zero.");
        0
     end_if
    end_if
  end_if
end_proc:

Now the procedure S displays the status messages:

S(0)
Is 0 a real number?
0 is a real number
Is 0 a positive number?
0 is not a positive number
Is 0 a negative number?
0 is not a negative number
0 is zero.