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
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
Peter 2025년 2월 19일
I want to change the variable "Vd_hfi" before running init_model m-script from "PreLoadFcn" so parametrs calculated by this "init_model" m-script are update each before simulink model run.
So how can I achive it?
Fangjun Jiang
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.
Peter
Peter 2025년 2월 19일
편집: Peter 2025년 2월 19일
Yes, Vd_hfi is used in init_model m-script and Vd_hfi is required for other parametrs of simulation (simulations parametrs are depandent of this value) ...
So how can I use "Multiple Simulations" where I need to change this Vd_hfi parametr per each simulation run and other parameters are depandable on it and calculated via init_model?
Basically, the Vd_hfi is the input for init_model m-script.
Fangjun Jiang
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
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
Peter 2025년 2월 20일
이동: Fangjun Jiang 2025년 2월 20일
I have a Simulink test toolbox .. how can that tlbx be used for this purpose?
Thank you very much for help.
Fangjun Jiang
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.
Peter
Peter 2025년 2월 24일
편집: Peter 2025년 2월 24일
How to go about when the "init_model" starts with
clear all
close all
clc
parameters I need to change are within init_model after these first lines so running simulink test will clear out the parametrs which supposed to changed ..
Is it really helpful to use Simulink test and will perfporme expected behaviour - is it worth it?
by review Simulink Test capabilities it seems not providing scenarios where params are precalculated with init_model M-sciprs and preloaded but just for pure Simulink models ....
Fangjun Jiang
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
Peter 2025년 2월 24일
이동: Fangjun Jiang 2025년 2월 24일
I'm a new to Simulink test and IMHO - unfortunatelly Simulink Test is to compilcate it to use in this scenario ....
Fangjun Jiang
Fangjun Jiang 2025년 2월 24일
It is a little difficult to get use to Simulink Test.
Peter
Peter 2025년 2월 25일
Since I'm using a legacy code and it's constricted as such - the init_model is a M-script which is used to initialize the Simulink model and afterwards I run the model where I'm checking the results based on initial configuratuion by M-script.
@Fangjun Jiang can you adice "better way" to cosntruct the callback - ideally reuse the legacy code?
Fangjun Jiang
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.
but at init_model there is more calculation and as start is
clear all;close all;clc;
mentioned approach unfortunatelly is not working for me ....
Fangjun Jiang
Fangjun Jiang 2025년 2월 25일
Either remove these statements, or move the "init_model" to PreLoadFcn and set your own InitFcn.
Peter
Peter 2025년 2월 25일
이동: Fangjun Jiang 2025년 2월 25일
moving to PreLoadFcn does not work

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Verification, Validation, and Test에 대해 자세히 알아보기

제품

릴리스

R2024b

질문:

2025년 2월 19일

이동:

2025년 2월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by