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

1 vue (au cours des 30 derniers jours)
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

Réponses (1)

Shuba Nandini
Shuba Nandini le 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

Catégories

En savoir plus sur Run Multiple Simulations dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by