Azzera filtri
Azzera filtri

How to start, then pause, then resume (etc) Simulink from Matlab, as in a 'for' loop?

3 visualizzazioni (ultimi 30 giorni)
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!!

Risposte (1)

Saffan
Saffan il 3 Mag 2023
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.

Categorie

Scopri di più su Event Functions in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by