How to use 'pause' function in Matlab Function Block?

6 次查看(过去 30 天)
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?

回答(1 个)

Rajanya
Rajanya 2025-2-19
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!

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by