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

15 次查看(过去 30 天)
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 !

回答(1 个)

Samatha Aleti
Samatha Aleti 2020-1-27
编辑:Samatha Aleti 2020-1-28
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 个评论
Recep Araz
Recep Araz 2020-1-29
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programmatic Model Editing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by