Plotting four lines in each of three subplots but only the last line is showing up
5 次查看(过去 30 天)
显示 更早的评论
Summary: Ive got a [3x1] subplot structure. Trying to plot four lines on each plot. Subplot 1 plots just fine. For some reason the last two are only plotting the last of the four lines. Why isn't hold on working?
Code:
if true
% code
% Change directory
directory = pwd;
posdir = strcat(directory,'\Pos');
cd(posdir);
files = dir(posdir);
% Read in files
% Trial # 9, under threshhold, correct detect
filename1 = files(3).name;
[hip1,txt,raw] = xlsread(filename1,'Q:Q');
[shoulder1,txt,raw] = xlsread(filename1,'AS:AS');
[head1,txt,raw] = xlsread(filename1,'BU:BU');
% Trial 11, at threshhold, correct detect
filename2 = files(4).name;
[hip2,txt,raw] = xlsread(filename2,'Q:Q');
[shoulder2,txt,raw] = xlsread(filename1,'AS:AS');
[head2,txt,raw] = xlsread(filename1,'BU:BU');
% Trial 21, at threshhold, incorrect detect
filename3 = files(5).name;
[hip3,txt,raw] = xlsread(filename3,'Q:Q');
[shoulder3,txt,raw] = xlsread(filename1,'AS:AS');
[head3,txt,raw] = xlsread(filename1,'BU:BU');
% Trial 32, over threshhold, correct detect
filename4 = files(6).name;
[hip4,txt,raw] = xlsread(filename4,'Q:Q');
[shoulder4,txt,raw] = xlsread(filename1,'AS:AS');
[head4,txt,raw] = xlsread(filename1,'BU:BU');
% Subtract mean
x1 = (1:1:length(hip1))/250;
hip1 = (hip1 - mean(hip1));
hip2 = (hip2 - mean(hip2));
hip3 = (hip3 - mean(hip3));
hip4 = (hip4 - mean(hip4));
shoulder1 = (shoulder1 - mean(shoulder1));
shoulder2 = (shoulder2 - mean(shoulder2));
shoulder3 = (shoulder3 - mean(shoulder3));
shoulder4 = (shoulder4 - mean(shoulder4));
head1 = (head1 - mean(head1));
head2 = (head2 - mean(head2));
head3 = (head3 - mean(head3));
head4 = (head4 - mean(head4));
% Plot the data
figure(1)
clf(1)
grid on
sub1 = subplot(3,1,1);
hold on
plot(x1,hip1,'r');
plot(x1,hip2,'b');
plot(x1,hip3,'k');
plot(x1,hip4,'g');
xlabel('Time [seconds]');
ylabel('Displacement [mm]');
title('Vicon Hip Movement');
sub2 = subplot(3,1,2);
plot(x1,shoulder1,'r');
hold on
plot(x1,shoulder2,'b');
plot(x1,shoulder3,'k');
plot(x1,shoulder4,'g');
xlabel('Time [seconds]');
ylabel('Displacement [mm]');
title('Vicon Shoulder Movement');
sub3 = subplot(3,1,3);
plot(x1,head1,'r');
hold on
plot(x1,head2,'b');
plot(x1,head3,'k');
plot(x1,head4,'g');
xlabel('Time [seconds]');
ylabel('Displacement [mm]');
title('Vicon Head Movement');
legend('T09BET','T11ATC','T22ATI','T32ABT','Location','Best');
cd(directory);
end
3 个评论
Walter Roberson
2015-6-8
I recommend Parent'ing all of your graphics calls http://uk.mathworks.com/matlabcentral/answers/22208-show-figure
回答(1 个)
Walter Roberson
2015-6-8
If only one line shows up it could be that the data you are plotting for each of the lines is close enough that the lines are on top of each other at that scale.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!