How to compile Simulink models before doing simulation?
249 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Kaustubha Govind
2013 年 7 月 12 日
Try open_system('myModel') if myModel is the name of your model. This just opens the model, but doesn't compile it.
採用された回答
Kaustubha Govind
2013 年 7 月 12 日
You can use the modelname command to compile the model. For example, if your model is named myModel.mdl or myModel.slx, use the following set of commands:
myModel([], [], [], 'compile')
myModel([], [], [], 'term')
Note that Simulink will still need to perform some compilation tasks when you run the simulation, but if you have Stateflow charts, MATLAB Function blocks, or referenced models, it will definitely help to pre-compile your model.
9 件のコメント
Han Geerligs
2024 年 9 月 24 日
when trying this approach I found that it doe not work for models with Accelerator mode. It reports
'Accelerator mode is not supported through the model command.'
Any suggestion how to solve this?
--Han
Philipp
2024 年 10 月 21 日
Hint, as I struggled a while on this:
If the name of your model is stored in a variable e.g. testMdlName, then you can not execute
testMdlName([], [], [], 'compile')
I got the error: Index in position 4 exceeds array bounds. Index must not exceed 1.
But you can do this:
eval( [testMdlName '([], [], [], ''compile'')'] )
その他の回答 (2 件)
Brian Kim
2023 年 5 月 19 日
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 件のコメント
August
2024 年 4 月 16 日
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!
参考
カテゴリ
Help Center および File Exchange で Schedule Model Components についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!