'hold on' not working with for loop
8 views (last 30 days)
Show older comments
I'm trying to plot multiple lines on the same graph using a for loop:
for i=1:imax
path=raypath3(frange(i), hnprofile, ds, minang, maxang, angstep, xmax);
plot(path(1,:),path(2,:))
hold on
end
hold off
When I run the code, it plots each line on a separate graph (so if imax is 3, I end up wih 3 different graphs). The hold on command doesn't seem to be doing anything. I've looked at similar questions that have already been asked but none of them have fixed my problem.
EDIT:
I have fixed the problem! I needed to create a figure and say hold on before the for loop.
figure
hold on
for i=1:imax
path=raypath3(frange(i), hnprofile, ds, minang, maxang, angstep, xmax);
plot(path(1,:),path(2,:))
end
(I also didn't need to say hold off at the end).
0 Comments
Answers (0)
See Also
Categories
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!