How to compile Simulink models before doing simulation?
Mostra commenti meno recenti
I'm working on a MATLAB script that will run different Simulink models but everytime I load one using sim(myModel) it takes an awful lot of time and I need its execution to be practically immediate.
Is there a way to compile at the start of the script and later on when I need to run the simulation just tell it 'play' somehow so that it will run without taking time to load anything else? Or is there any other workaround for this problem?
By the way I tried using
open_system(myModel)
and it gives me an error: Invalid Simulink object handle
Unfortunately that's all it says, but if that's the answer to compiling before the simulation, any ideas of what the problem could be?
Thanks.
1 Commento
Kaustubha Govind
il 12 Lug 2013
Try open_system('myModel') if myModel is the name of your model. This just opens the model, but doesn't compile it.
Risposta accettata
Più risposte (3)
Brian Kim
il 19 Mag 2023
You can use also use set_param as well to compile the model
set_param(modelName, 'SimulationCommand', 'update')
The difference is that in scripting workflow, this will wait until the compilation is finished.
1 Commento
August
il 16 Apr 2024
When I use that command I get the build text through the command window and eventually get the error:
Warning: Non-scalar data in first argument to set_param is detected.
Only first handle in the matrix is processed.
Invalid Simulink object handle
However, when I run:
set_param('modelName','SimulationCommand', 'update')
it runs the command and does not produce any comments in the command window.
Two questions:
- do you know why running the set_param() command with my modelName NOT in quotes does what I want it to do but throws the invalid simulink object handle?
- Is there a way to get the output of set_param() with my ModelName in quotes to produce an output in the command window?
Thanks for your help!
Azzi Abdelmalek
il 12 Lug 2013
0 voti
To improve your simulation look at this link
1 Commento
Rednar
il 12 Lug 2013
Abhisar
il 5 Lug 2025
0 voti
There's a lot easier way to do this.
Just turn on fast restart in the SIMULATE tab in your simulink model. Now, whenever you call simOut, the model will not compile everytime, so you can change a variable from your matlab scipt and run the model iteratively, way faster than before.
Categorie
Scopri di più su Prepare Model Inputs and Outputs in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!