Fail to plot graphs in a for loop, hold on doesn't work

9 ビュー (過去 30 日間)
allan
allan 2017 年 1 月 4 日
コメント済み: allan 2017 年 1 月 6 日
Hi all,
My codes intend to plot a graph from two tables using a for loop, but the "hold on" function does not work. No matter where I put the "hold on" (i.e. inside or outside the loop), only the last plot is shown in the figure. I am using Matlab2016a
hold on
for filei=0: ((length(vel_faster.Properties.VariableNames))-4)/3
column_y=3*filei+2; % y coordinates
column_yL=3*filei+3; % y coordinates
column_yU=3*filei+4; % y coordinates
column_b=3*filei+2; % y coordinates
column_bL=3*filei+3; % y coordinates
column_bU=3*filei+4; % y coordinates
figurei=filei+1; %file loop
% Plot lines from first table
hold on;
x=vel_slower.(1);
y=vel_slower.(column_y); %line1
yL=vel_slower.(column_yL);%line2
yU=vel_slower.(column_yU);%line3
figure(figurei); plot(x,y,'k-');
figure(figurei); plot(x,yU,'m--');
figure(figurei); plot(x,yL,'m--');
% Plot lines from second table
a=vel_faster.(1);
b=vel_faster.(column_b); %line4
bL=vel_faster.(column_bL); %line5
bU=vel_faster.(column_bU); %line6
figure(figurei); plot(a,b,'r-');
figure(figurei); plot(a,bL,'g:');
figure(figurei); plot(a,bU,'g:');
hold all;
end

採用された回答

Fangjun Jiang
Fangjun Jiang 2017 年 1 月 4 日
Put the "hold on" command after the figure() line.
"hold" holds the current plot.
"figure(H)" makes H the current figure. If Figure H does not exist, and H is an integer, a new figure is created with handle H.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by