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

1 Ansicht (letzte 30 Tage)
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

Antworten (1)

Shuba Nandini
Shuba Nandini am 6 Okt. 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

Kategorien

Mehr zu Run Multiple Simulations finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by