Using for loop to plot multiple plots on the same graph
Show older comments
I am trying to plot 3 plots on the same graph , I believe the best way to do this would be a for loop. I'd like to keep the paramaters that I am changing flexible, so I would like to call them from an array. This is the code that I have so far, where 'Tau1' is a parameter that varies the function 'G_fun'. I am only getting one plot which the legend is labelling to be the last plot with Tau1 = 1e-5. How would I be get a different plot of G_fun for each value of Tau1 on the same graph? Thank you in advance for any help.
N = [1e-3,1e-4,1e-5];
for i = 1:1:3
Tau1 = N(i); % the parameter to be changed
if N(i) == 1e-3
figure
hold on
end % end if
bode(G_fun);
end
hold off
legend('Tau1 1e-3', 'Tau1 1e-4', 'Tau1 1e-5')
grid on
title('System Bode Plots')
1 Comment
DGM
on 2 Apr 2021
What is G_fun? How is it getting the parameter Tau1?
Accepted Answer
More Answers (1)
William Rose
on 2 Apr 2021
2 votes
Try putting the figure command and the hold on command outside and before the for loop.
Categories
Find more on Graphics Performance in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!