Importing a SIMULINK model to workspace and using the model for output generation

24 visualizaciones (últimos 30 días)
Hey there,
I created a model in SIMULINK and I have 16 signals that I want to feed in to this system and obtain the outputs individually with coding in MATLAB.
I can do this one by one using the From Workspace and To Workspace Blocks in SIMULINK, however I want to do this many times using a single for loop in MATLAB.
How can I load the system to MATLAB workspace, feed my signals one by one and store the output?
Thanks a lot !

Respuestas (1)

Samatha Aleti
Samatha Aleti el 27 de En. de 2020
Editada: Samatha Aleti el 28 de En. de 2020
Hi,
According to my understanding, you are trying to run a SIMULINK model with different values each time one after other, from MATLAB. You can do this with the help of sim” command and “set_param” command. Here is a sample MATLAB script to do this:
y = zeros(1,10); % Let
A = 0; % Let
for i = 1:10
A = A +1;
set_param('SimLoop/Constant','Value','A') % Changing the constant value for each simulation
out = sim('SimLoop'); % Run model
y(i) = out.yout.Data; % Save output
end
I have attached the SIMULINK model SimLoopthat I used in this example for better understanding. This is basic example to help you understand how to use commands to load and configure a SIMULINK model, you may have to add or modify to get your desired behaviour.
You can also use the command “parsim” to run multiple simulations in parallel, Refer the following document link for detailed explanation:
Following is the document link on Programmatic Modeling:
  1 comentario
Recep Araz
Recep Araz el 29 de En. de 2020
Thank you so much for your help! I learned about the set_param method and I tried to use it.
In your example however, this error occurs
Invalid Simulink object name: SimLoop/Constant
Caused by:
Error using Untitled (line 5)
No block called 'Constant' could be found.
In my case, I am trying to get and set the PID parameters(Kp,Ki,Kd,N) of the PID Controller Block inside a subsystem in my model but I think it's not possible to set the PID parameters with the set_param method.

Iniciar sesión para comentar.

Categorías

Más información sobre Programmatic Model Editing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by