'hold on' not working with for loop

8 Ansichten (letzte 30 Tage)
Ben Wadsworth
Ben Wadsworth am 14 Mär. 2021
Bearbeitet: Ben Wadsworth am 14 Mär. 2021
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).

Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by