Fail to plot graphs in a for loop, hold on doesn't work
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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 Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!