How run Simulink model automatically from itself if a condition is met?
12 views (last 30 days)
Show older comments
Ester Panea Murillo
on 5 Jun 2020
Commented: Ester Panea Murillo
on 5 Jun 2020
I need to run simulink twice automatically only after the first run (this is because I need the data from the first simulation in order to feed the next one - this already works in my model by an InitFCN code).
I tried implementing the next code in StopFCN callback, but obviously it doesn't work because "Termination of 'model_name' is in progress"
%no. runs counter
Number_Runs=Number_Runs+1
%only if number of run times is 2 automatically run simulink
if (Number_Runs - 1)==0
sim(SIMULINK_MODEL_L7); %%HERE IS WHERE I TRIED TO RUN BY CODE
end
I can't come across any solution to implement this.
Hope I explained well.
-Ester
0 Comments
Accepted Answer
Fangjun Jiang
on 5 Jun 2020
Edited: Fangjun Jiang
on 5 Jun 2020
Try it in PostSaveFcn, or have an independent and separate M-script to control your simulation.
3 Comments
Fangjun Jiang
on 5 Jun 2020
Might it be just a simple syntax error, like
open_system('f14');
sim('f14')
or you could do
model='f14'
sim(model)
More Answers (0)
See Also
Categories
Find more on Model, Block, and Port Callbacks 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!