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 input

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.




Pref::postInput allows to set user actions directly after input.

After entering any MuPAD® command x, say, and sending this command to the kernel, f(x) is called before the kernel starts to process the input. This happens for any input until the post-input is switched off via the call Pref::postInput(NIL).

The function f implicitly uses the option hold, i.e., f sees the input command as entered and parsed without any evaluation.

f cannot change the input command that is sent to the kernel for evaluation. However, f can store the input in some global variable for later processing, or some other actions can be performed.

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

Pref::postInput, possibly in conjunction with Pref::postOutput, is useful for initializing variables to compute status information such as the execution time for the command that is to be executed. See Example 2.


Example 1

The post-input function sees the input as entered, i.e., before evaluation by the kernel:

Pref::postInput(proc() begin 
  print(Unquoted, "input" = args()) 
1 + 2
input = 1 + 2

1 + 2, x = sin(0.1)
input = (1 + 2, x = sin(0.1))

x := 1234; y := 5678
input = (x := 1234)

input = (y := 5678)

Post-input is switched off. This command calls the post-input function for the very last time:

input = Pref::postInput(NIL)
delete x, y:

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::postOutput compares the current time and the starting time TIME.

Pref::postInput(() -> (TIME:= time())):
Pref::postOutput(() -> "Time: ".expr2text((time() - TIME)*msec)):
int(cos(x)*exp(sin(x)), x)

Time: 40 msec 

Time: 40 msec
Pref::postInput(NIL): Pref::postOutput(NIL): 
delete TIME:

Example 3

As another example of using Pref::postInput for storing information to influence the output, we combine it with Pref::output to include (a rendered version of) the input and the result:

Pref::postInput(() -> (LASTINPUT := args())):
Pref::output(() -> val(LASTINPUT) = args()):

This makes MuPAD write "input = result" to the screen, while leaving the history (accessible by %) intact:

int(x, x);
sum((-1)^i/(2*i+1), i=0..infinity);



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

Return Values

Previously set post-input function.

See Also

MuPAD Functions

Was this topic helpful?