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!