How do I tune a parameter in an accelerated model reference while the simulation is running?

I have a parameter in a model reference that I would like to tune while the simulation is running in accelerator mode. How do I do this?

 채택된 답변

There are many ways to tune a parameter in accelerated model reference while the simulation is running. Consider the following model and model reference.
Tune with Simulation Object (24a and later)
The easiest way to tune a parameter while simulating is to use the Simulation Object introduced in 24a.
set_param(mdl,'SimulationMode','acc') sl = simulation('model'); gainRM = 1; sl.start pause(1) sl.setVariable('gainRM',2) pause(1) sl.stop; sl.SimulationOutput.yout{1}.Values.Data(end) %should be 2
Tune in Normal Mode (No Update)
In normal mode you can tune the variable directly if you use set_param and it will work.
set_param(mdl,'SimulationMode','normal') gainRM = 1; set_param(mdl,'SimulationCommand','start'); pause(1) gainRM = 2; set_param('Ref_Mod/Constant','Value','gainRM'); pause(1); set_param(mdl,'SimulationCommand','stop'); out.yout{1}.Values.Data(end) %should be 2
Tune in Accel Mode (With Update)
In accelerator mode, you need to trigger an update for the change to propagate.
set_param(mdl,'SimulationMode','acc') gainRM = 1; set_param(mdl,'SimulationCommand','start'); pause(1) gainRM = 2; set_param(mdl,'SimulationCommand','update'); pause(1); set_param(mdl,'SimulationCommand','stop'); out.yout{1}.Values.Data(end) %should be 2
Tune in Accel Mode (With Model Arguments)
If you do not want to trigger an update, make the parameter a model then you do not need to trigger an update.
set_param(mdl,'SimulationMode','acc') gainRM = 1; set_param(mdl,'SimulationCommand','start'); pause(1) gainRM = 2; instSpecParams = get_param('model/Model1','InstanceParameters'); set_param('model/Model1','InstanceParameters',instSpecParams); pause(1); set_param(mdl,'SimulationCommand','stop'); out.yout{2}.Values.Data(end) %should be 2

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Simulink에 대해 자세히 알아보기

제품

릴리스

R2020b

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by