How to start, then pause, then resume (etc) Simulink from Matlab, as in a 'for' loop?
3 次查看(过去 30 天)
显示 更早的评论
Hello! I am working on a Simulink model for a scanner. The functioning should be: move to next position, scan data, then move again.
I have constructed in Matlab a code that solves the movement and the scanning data from the beginning, then Simulink reproduces this. However, I would like it to be that way:
Imagine I have to scan ten points. Then, the model should move to ten positions, and scan in each of them. The way I want it to work is: start in a loop (i=1:10). In i = 1, the model should move to the proper position, then scans the data. Then Simulink updates such i to i = i+1, and then moves, then scans data. Then stop when all the points have been scanned. How could I manage that "start-->stop-->resume--> stop" algorithm in which Simulinks updates the "i" variable that is in my Matlab Script?
Thank you!!
0 个评论
回答(1 个)
Saffan
2023-5-3
You can achieve this by using “sim” command to start the simulation and “set_param” command to pause, continue, stop, etc. Firstly, modify your model to take input of the position to be scanned. Then iterate over the positions, say ‘i’, and execute these commands in the loop:
sim('your_model', 'simIn', num2str(i));
set_param('your_model', 'SimulationCommand', 'continue');
The “sim” command simulates the model by taking the input of the position to be scanned and “set_param” function sets the ‘SimulationCommand’ parameter to ‘continue’ which allows the simulation to continue from its last point rather than starting over in the next iteration.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!