How to create a variables in simulink of a pre-set variables within a Simulink.SimulationInput
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Shuba Nandini
2023-10-6
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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!