How to create a variables in simulink of a pre-set variables within a Simulink.SimulationInput

1 view (last 30 days)
I am using a for loop to conduct parallel simulations via parsim
for i=1:iterations
%LOAD SYSTEM
in(i)=Simulink.SimulationInput('MDL');
in(i) = in(i).setVariable('X',1000,'Workspace','MDL');
I want to create an additional variable in the following way:
in(i) = in(i).setVariable('Y',X*10,'Workspace','MDL');
I hope you could help me

Answers (1)

Shuba Nandini
Shuba Nandini on 6 Oct 2023
Hello Rafael,
It is my understanding that you want to create an additional variable in Simulink using the "setVariable" function. However, to use the value of ‘X’ for setting ‘Y’, you need to first get the value of ‘X’.
You can follow the below workaround to set the value of ‘Y’,
for i=1:iterations
%LOAD SYSTEM
in(i)=Simulink.SimulationInput('MDL');
X_value = 1000; % Set X value
in(i) = in(i).setVariable('X', X_value,'Workspace','MDL');
% Create an additional variable Y
Y_value = X_value * 10; % Use the X value for setting Y
in(i) = in(i).setVariable('Y', Y_value,'Workspace','MDL');
end
You can also use “getVariable” function to fetch the value of ‘X’ and assign it to ‘Y’. “getVariable” function returns a value of variable in the model workspace of a model.
Refer to the following documentation to know more about “getVariable” function”:
Hope this helps!
Regards,
Shuba Nandini

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!