Save and plot the Simout from simulink for every iteration of For loop applied in MATLAB
44 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
x = zeros(102,80);
y = zeros(102,80);
voltage = zeros(102,1);
time = zeros(102,1);
voltage = ans.simout.data;
time = ans.simout.time;
Pavan Guntha on 30 Aug 2021
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,:) = ans.simout.data;
time(i,:) = ans.simout.time;
You could also use 'hold' command to plot multiple graphs onto a single figure for comparison.
Hope this helps!