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

조회 수: 8 (최근 30일)
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);
  댓글 수: 2
Rhea Chandy
Rhea Chandy 2021년 2월 4일
From what I understand, you're trying to update the variables 'A' and 'R' programmatically, but the variable R is not updating as expected. Can you share the model you're working on so that I can recreate the issue and investigate further?
Carlos Santiago Moreno Lozano
Carlos Santiago Moreno Lozano 2021년 2월 5일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Mark McBroom
Mark McBroom 2021년 2월 6일
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')
Thanks.
Mark.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Foundation and Custom Domains에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by