How can I change a parameter in a Simulink block using code setVariable?

12 views (last 30 days)
I do a simply circuit simulation, a voltage source DC and a resistence, i create 2 variables A = amplitude DC source and R = resistance, when try change this variables ony change A but R not change in the block so the out is not the rigth.
I do this
In = Simulink.SimulationInput('Sim');
In = In.setVariable('A',10);
In = In.setVariable('R',20);
In = simulink.compiler.configureForDeployment(In); % I need this
out = sim(In);
Carlos Santiago Moreno Lozano
I need create an app web with this simulation, so if I change in the app R value, in the simulation should change too but the code dosn't work well.

Sign in to comment.

Accepted Answer

Mark McBroom
Mark McBroom on 6 Feb 2021
Since the variables you are trying to change are in the Model Workspace, you need to add an optional argument specifying this.
In = In.setVariable('R',2, 'Workspace', 'RL')
In = In.setVariable('A',20, 'Workspace', 'RL')

More Answers (0)

Community Treasure Hunt

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

Start Hunting!