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

13 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Fangjun Jiang
Fangjun Jiang am 5 Jun. 2020
Bearbeitet: Fangjun Jiang am 5 Jun. 2020
Try it in PostSaveFcn, or have an independent and separate M-script to control your simulation.
  3 Kommentare
Fangjun Jiang
Fangjun Jiang am 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 am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Model, Block, and Port Callbacks finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by