How to use 'pause' function in Matlab Function Block?
5 views (last 30 days)
Show older comments
I'm able to run the following code in Matlab Command Window, which is giving me the output I'm looking for, i.e. printing the respective elements of matrix x and y after a three second gap:
x = [1 2 3];
y = [4 5 6];
x(1)
y(1)
pause(3);
x(2)
y(2)
pause(3);
x(3)
y(3)
However, I want a Matlab Function Block to process this code and display the answers in a 'display' block in Simulink. I set up the following model:


I'm able to run this code too, but the output is displayed in the Matlab Command Window (shown below), and not the 'display' blocks. Also, the code runs till the simulation time is over and this gives the required output multiple times. Is there any way to run the simulation only once?

0 Comments
Answers (1)
Rajanya
on 19 Feb 2025
You can either set the 'Step size' of the solver to be equal to 'Stop Time' (assuming 'Start Time is 0') or just set the 'Stop Time' to 0 for the simulation to run "only once".
Additionally, display blocks update their outputs only after a complete time step. As a result, they will display only the last pair of values, which in this case is (3,6).
Thanks!
0 Comments
See Also
Categories
Find more on Simulink Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!