Actions after input
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.
f) Pref::postInput(NIL) Pref::postInput()
Pref::postInput allows to set user actions
directly after input.
After entering any MuPAD® command
say, and sending this command to the kernel,
called before the kernel starts to process the input. This happens
for any input until the post-input is switched off via the call
f implicitly uses the
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,
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
Pref::postInput, possibly in conjunction
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.
The post-input function sees the input as entered, i.e., before evaluation by the kernel:
Pref::postInput(proc() begin print(Unquoted, "input" = args()) end):
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:
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
the current time and the starting time
Pref::postInput(() -> (TIME:= time())): Pref::postOutput(() -> "Time: ".expr2text((time() - TIME)*msec)):
Time: 40 msec
Time: 40 msec
Pref::postInput(NIL): Pref::postOutput(NIL): delete TIME:
As another example of using
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
int(x, x); sum((-1)^i/(2*i+1), i=0..infinity); sin(%)
Previously set post-input function.