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

9 visualizaciones (últimos 30 días)
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

Respuestas (1)

Shuba Nandini
Shuba Nandini el 6 de Oct. de 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

Categorías

Más información sobre Run Multiple Simulations en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by