How run Simulink model automatically from itself if a condition is met?

12 views (last 30 days)
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

Accepted Answer

Fangjun Jiang
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
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)
Ester Panea Murillo
Ester Panea Murillo on 5 Jun 2020
Thank you Fangjun, it now works propertly with:
open_system ('model_name');
sim('model_name');
(Although I had already manually opened the simulink window, it turns out that it needs anyway the "open_system" command in the M-file).
Thank you again.

Sign in to comment.

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!