This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Actions after output

MuPAD® notebooks are not recommended. 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.




After the result x, say, of a MuPAD® command is printed on the screen, f(x) is called and executed before the next prompt for user input appears. This happens for any output until the post-output is switched off via Pref::postOutput(NIL).

After the usual output of the result x of a MuPAD command, the return value of f(x) is printed on the screen with PRETTYPRINT = FALSE. However, f(x) does not return any value to the MuPAD session. It cannot be accessed via last.

Pref::postOutput() returns the current value of the post-output function or NIL, respectively.

Pref::postOutput, possibly in conjunction with Pref::postInput, can be used to produce status information after each output. One may think of timer informations, memory usage, result types etc.


Example 1

Here, Pref::postOutput is used to enumerate the output line and display the type of the result. It uses the global variable LineNumber which must be initialized before any output is produced. The definition of the post-output operation as well as the initialization of the global variable can be done in the file "" which is read automatically during start-up.

    LineNumber:= LineNumber + 1;
    "Out[" . expr2text(LineNumber). "]: ".
    "type = ".expr2text(op(map([args()], domtype)));
LineNumber:= 0:
int(x^5*exp(-x), x)

Out[1]: type = DOM_EXPR
int(x^5*exp(-x), x = 0..infinity),
numeric::int(x^5*exp(-x), x = 0..infinity)

Out[2]: type = DOM_INT, DOM_FLOAT

The following print command returns the void object null() to the MuPAD session. The output of null() is suppressed:

print("print returns the void object")

The following command is terminated by a semicolon to suppress the output. Consequently, no post-output is created, either.

x := sin(2):

Post-output is switched off:

Pref::postOutput(NIL): delete LineNumber, x:

Example 2

For any command, the run time is to be computed and displayed. The function declared in Pref::postInput sets a global timer value TIME after each input. After the output of the result, the function declared in Pref::postInput compares the current time and the starting time TIME. The current TEXTWIDTH is used to prepend some suitable whitespace via stringlib::format to flush right the timer information:

Pref::postInput(() -> (TIME:= time())):
  proc() begin
   stringlib::format("Time: ".expr2text(time() - TIME)." msec",
                     TEXTWIDTH-1, Right)
int(x^10*exp(-x), x)

                                           Time: 84.005 msec 
Pref::postInput(NIL): Pref::postOutput(NIL): 
delete T, TIME:

Example 3

The following post-output lists all identifiers with properties in the result of the last MuPAD command. It extracts the indeterminates via indets and uses property::hasprop to query whether they have properties:

    select(indets({args()}), property::hasprop);
    "identifiers with properties: " . expr2text(op(%))
assume(0 < a < b): a + b + c

identifiers with properties: a, b
Pref::postOutput(NIL): delete a, b:



The function to be executed after output: a procedure. The default value of this function is NIL (no post-output).

Return Values

Previously set post-output function.

See Also

MuPAD Functions

Was this topic helpful?