Plotting four lines in each of three subplots but only the last line is showing up
Show older comments
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 Comments
Joseph Cheng
on 8 Jun 2015
I simplified it a bit to use some dummy data it works for me.
x = randi(10,10,4);
colors = 'bgrk';
figure(1)
clf(1)
grid on
sub1 = subplot(3,1,1);
hold on
for ind = 1:4
plot(x(:,ind),colors(ind));
end
sub2 = subplot(3,1,2);
plot(x(:,1),colors(1));
hold on
for ind = 2:4
plot(x(:,ind),colors(ind));
end
sub3 = subplot(3,1,3);
plot(x(:,1),colors(1));
hold on
for ind = 2:4
plot(x(:,ind),colors(ind));
end
Now i would ask are you sure there is valid data in sholders1-3 and head1-3? Are you able to plot the data head and shoulders separately in a new figure and only when trying to do it in subplot it fails?
Zeke Merchant
on 8 Jun 2015
Walter Roberson
on 8 Jun 2015
I recommend Parent'ing all of your graphics calls http://uk.mathworks.com/matlabcentral/answers/22208-show-figure
Answers (1)
Walter Roberson
on 8 Jun 2015
0 votes
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.
Categories
Find more on Subplots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!