'hold on' not working with for loop

9 ビュー (過去 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 Center および File Exchange2-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