Clear Filters
Clear Filters

Save and plot the Simout from simulink for every iteration of For loop applied in MATLAB

12 views (last 30 days)
I Wish to change the parameter of Block T1 of Simulink and then i need to plot the graph and compare these 5 plots.
Hence i have for loop in MATLAB and controlled the paramters from MATLAB script using set_param.
Please refer the profgram below.
The problem i m not getting the ouput for 5 different plots and i end up getting only the last value of the iteration. i.e
i get the output values for only parameter with block T1 = '1'.
how can i save the output from simout at each iteration and plot the graphs.
Please help. Thanks in Advance.
I m writing my program below for reference
for i = 1:5
if i==1
elseif i==2
elseif i==3
elseif i==4
x = zeros(102,80);
y = zeros(102,80);
voltage = zeros(102,1);
time = zeros(102,1);
voltage =;
time = ans.simout.time;
x(:,i)= voltage;
y(:,i)= time;

Answers (1)

Pavan Guntha
Pavan Guntha on 30 Aug 2021
Hello Mayur,
For storing output of simout at each iteration, you could create a 2D array and use 'i' as index to write data into it as illustrated below:
voltage(i,:) =;
time(i,:) = ans.simout.time;
You could also use 'hold' command to plot multiple graphs onto a single figure for comparison.
Hope this helps!


Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!