Plotting with a for loop
Show older comments
Hello all,
I was wondering if it was possible to use a for loop to plot certain lines on my figures. For example, my 1st plot will contain all 4 lines while my 2nd plot will omit the very 1st line in my 1st plot and only plot the remaining 3 lines. My 3rd plot will then omit the first 2 lines and only plot the remaining 2 lines. Instead of adding the code manually, is there a simpler approach?
% % x,y,z,a,b = My datasets
tiledlayout(3,1);
figure;
nexttile; % 1st plot with all 4 lines
plot(x,y,'r-');
hold on;
plot(x,z,'b-');
hold on;
plot(x,a,'k-');
hold on;
plot(x,b,'k-');
nexttile; % 2nd plot with 3 lines
plot(x,z,'b-');
hold on;
plot(x,a,'k-');
hold on;
plot(x,b,'m-');
nexttile; % 3rd plot with 2 lines
plot(x,a,'k-');
hold on;
plot(x,b,'m-');
Accepted Answer
More Answers (0)
Categories
Find more on Annotations 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!