Run Simulink iteration by iteration in MATLAB script

조회 수: 6 (최근 30일)
Katrine G. Andersen
Katrine G. Andersen 2015년 11월 13일
댓글: Katrine G. Andersen 2015년 11월 14일
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에서 Simulink Functions에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by