Fail to plot graphs in a for loop, hold on doesn't work
이전 댓글 표시
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
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!