How to apply App Designer output to Constant of simulink model ?

3 Ansichten (letzte 30 Tage)
AK
AK am 26 Mär. 2024
Kommentiert: AK am 27 Mär. 2024
Can anyone tell me what I am missing ?
*****************************
With push button callback I am starting model simulation with
set_param(app.Modelname,'SimulationCommand','start');
**********************************************
I have discrete knob in App designer panel. Which I want to use to give input as (modelsignal=0,1,2)
My call back is as below
********************
knob = app.DynamicModeKnob.Value;
if strcmp(knob,'Up')
updnsw = 1;
assignin('base','modelsignal',updnsw);
elseif strcmp(knob,'Down')
updnsw = 2;
assignin('base','modelsigna1',updnsw);
else
updnsw = 0;
assignin('base','modelsignal',updnsw);
*******************************************************
Simulink Model has constant with name 'modelsignal'.
When i run the app and give command to run model,
In workspace I see modelsignal value changing as 0,1,2 when i press knob to off,Up,Down.
Problem is :
Model constant doesnt get value as 0,1,2 it remains 1.
Can anyone help me to understand what step i am missing ?

Akzeptierte Antwort

Fangjun Jiang
Fangjun Jiang am 26 Mär. 2024
The workspace value is compiled/built for simulaiton only once when the model is initialized. It will not be updated to the model simulation when the value is changed during the simulaiton.
You may use set_param() to update a block parameter while the simulation is running if this parameter is tunable. For example, if 'modelsignal' is used by a Constant block, you may be able to set_param('ConstantBlock','value',num2str(updnsw )).
  1 Kommentar
AK
AK am 27 Mär. 2024
Thanks .
It worked with set_param('modelname/blockname','value','numberhere ');

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Simulink finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by