'hold on' not working with for loop

조회 수: 8 (최근 30일)
Ben Wadsworth
Ben Wadsworth 2021년 3월 14일
편집: Ben Wadsworth 2021년 3월 14일
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개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by