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

5 次查看(过去 30 天)
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 ?

采纳的回答

Fangjun Jiang
Fangjun Jiang 2024-3-26
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 )).

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Environment Customization 的更多信息

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by