setVariable() used to specify variable in Simulink model within App Design not working
3 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
I hope somebody can help me on this because I have been troubleshooting this for many hours and my Google search did not yield any helpful answers.
I am creating an App of a Simscape model called 'head_loss' using App Design in MATLAB. I want to use a Knob to control one of the Model Workspace variables.
I know that I can use the setVariable() function to change the Model Workspace variable 'head' but whatever changes I've made to the value of the Knob in the App, the simulation run results remain the same, while I know that it should change.
A part of the code is below,
% create the simulation input
simInp = Simulink.SimulationInput('head_loss');
% set the parameters for this run
simInp = simInp.setVariable('head',app.ConstantHeadMPaKnob.Value); % <--- DOES NOT WORK
% configure simInp for deployment
simInp = simulink.compiler.configureForDeployment(simInp);
% DEBUG TIP: Comment out the line above for faster debug
% iterations when runnng this app in the MATLAB desktop.
% run
simOut = sim(simInp);
Thanks!
0 个评论
回答(1 个)
Ju-Yoen Baek
2022-7-14
I think there is something written in the Mathworks, but there is no detailed explanation at all:(
So I faced the same problem in AppDesign...
Try changing the code as follows!
simInp = simInp.setVariable('head',app.ConstantHeadMPaKnob.Value,'Workspace','head_loss');
And before creating the App, you can use the Matlab code
to see that the Simulink results change depending on the value you set.
For example)
>> ConstantHeadMPaKnob = 10;
>> simInp = Simulink.SimulationInput('head_loss');
>> simInp = simInp.setVariable('head', ConstantHeadMPaKnob,'Workspace', 'head_loss');
>> simOut = sim(simInp);
Thank you, and good Luck!
1 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Environment Customization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!