setVariable() used to specify variable in Simulink model within App Design not working
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Ju-Yoen Baek
am 14 Jul. 2022
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 Kommentar
Thomas Hughes
am 9 Jul. 2023
Verschoben: Stefanie Schwarz
am 4 Mär. 2025
Thank you, Ju-Yoen! That fixed my code.
Siehe auch
Kategorien
Mehr zu Simulink Environment Customization finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!