Run Simulink iteration by iteration in MATLAB script

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

采纳的回答

Sebastian Castro
Sebastian Castro 2015-11-13
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dependency Analysis 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by