Run Simulink iteration by iteration in MATLAB script
2 views (last 30 days)
Show older comments
Katrine G. Andersen
on 13 Nov 2015
Commented: Katrine G. Andersen
on 14 Nov 2015
I have a Simulink model and a MATLAB script. I am collecting data from the Simulink model into the MATLAB script, meaning that I need to run the Simulink model iteration by iteration, because I need the data from my Simulink model in my MATLAB script. I have googled, and found one answer saying to write the following in my script:
sim('name_of_model', [tStart tFinal]);
but this only runs the model from 0 to x seconds, and not iteration by iteration. Can anyone please help me?
0 Comments
Accepted Answer
Sebastian Castro
on 13 Nov 2015
When you run a Simulink model from the command-line, it always runs the whole thing. There are some pause/continue controls, but that's not the way to go because you don't really have control over how many time steps run before you pause the model.
I would recommend taking the code in your MATLAB script and placing it into a MATLAB Function block. Then, your model can use that code at every time step as it runs, and can seamlessly accept/return data to/from the rest of the model.
- Sebastian
More Answers (0)
See Also
Categories
Find more on Dependency Analysis 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!