setVariable() used to specify variable in Simulink model within App Design not working

4 vues (au cours des 30 derniers jours)
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!

Réponses (1)

Ju-Yoen Baek
Ju-Yoen Baek le 14 Juil 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!

Catégories

En savoir plus sur Simulink Environment Customization dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by