Simulation manager with initFcn
古いコメントを表示
I'd need to run multiple simulation runs with using Simulation Manager "Multiple Simulations". My simulik model uses InitFcn callback function to initializate the model via matlab m-script. There are params which needs to be change per multiple simulation runs.
As pictured, I'd need to Vd_hfi to be change per simulation runs, it s defined in "init_model" m-script and this variable is used in Simulink model block.
As of now I am not able to chne the params for different values per simulations runs....
Is it possible to achieve this and so how?
回答 (1 件)
Fangjun Jiang
2025 年 2 月 19 日
0 投票
'InitFcn' is executed before the simulation starts, that is probably the reason that your parameter values set in the multiple simulation are over-written.
Usually, you can move the function calls in 'InitFcn' to 'PreLoadFcn' or 'PostLoadFcn' if it is only to set up some parameter values. Then use Simulation Manager to set up all the parameter values that need to be different between each simulation.
16 件のコメント
Peter
2025 年 2 月 19 日
Fangjun Jiang
2025 年 2 月 19 日
In your example, Vd_hfi is set as 100 in the first simulation and set as 250 in the second. Maybe Vd_hfi is also set a value in "init_model" thus the conflict.
If all the other calculation in init_model does not depend on Vd_hfi, then you can move init_model from InitFcn to PreLoadFun, then you are all set.
If there are some other calculations depending on Vd_hfi, then you need to modify init_model to remove the assignment of Vd_hfi.
Fangjun Jiang
2025 年 2 月 19 日
Okay, I tried an example. The callbacks are ignored when using this multiple simulation panel. It does not make sense. Need to look into this multiple simulation panel a little bit more.
Fangjun Jiang
2025 年 2 月 20 日
If you have parameters dependent on each other and it takes some calculatoin, this "Multiple Simulations" panel from Simulation Manager may not be the right tool to use. I know Simulink Test can do that but you needs the Simulink Test Toolbox.
Peter
2025 年 2 月 20 日
移動済み: Fangjun Jiang
2025 年 2 月 20 日
Fangjun Jiang
2025 年 2 月 20 日
Design your Simulink test cases, in the customized iterations, you can specify the parameter values for iteration and run scripts. Go through a tutorial if you never used Simulink Test before.
Fangjun Jiang
2025 年 2 月 24 日
It is not recommened to use all those "clear" commands but if you only work on one model, it should be fine. There are ways to better construct the callbacks.
Simulink Test is specifically designed for testing and it is defintely worth to learn and use it.
Peter
2025 年 2 月 24 日
移動済み: Fangjun Jiang
2025 年 2 月 24 日
Fangjun Jiang
2025 年 2 月 24 日
It is a little difficult to get use to Simulink Test.
Peter
2025 年 2 月 25 日
Fangjun Jiang
2025 年 2 月 25 日
Write a little script using for-loop. Set different values for Vd_hfi, use SimResult=sim('model') to run multiple simulations and save the results. The "init_model" is called the same way and no need to do any change.
Peter
2025 年 2 月 25 日
Fangjun Jiang
2025 年 2 月 25 日
Either remove these statements, or move the "init_model" to PreLoadFcn and set your own InitFcn.
Peter
2025 年 2 月 25 日
移動済み: Fangjun Jiang
2025 年 2 月 25 日
カテゴリ
ヘルプ センター および File Exchange で Verification, Validation, and Test についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!