How to plot a mean line for all subplots
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
timetry2
am 3 Okt. 2019
Kommentiert: timetry2
am 3 Okt. 2019
I have a code that gives the following subplots

but I need a mean line in the color green and make it look like the following:

So how would I create this green mean line. Thank you so much in advance and my code looks like the following currently
figure
y =Data.StrideTimeIntervals_15minTrial.PD(:,1);
subplot (3,4,1),plot (y, 'r')
title ('PD 1')
xlabel ('ISI #')
ylabel ('ISI (s)')
axis ([0,500,0.8,1.2])
disp ('PD 01 DONE')
y =Data.StrideTimeIntervals_15minTrial.PD(:,2);
subplot (3,4,2),plot (y, 'r')
title ('PD 2')
xlabel ('ISI #')
ylabel ('ISI (s)')
axis ([0,500,0.8,1.2])
disp ('PD 02 DONE')
y =Data.StrideTimeIntervals_15minTrial.PD(:,3);
subplot (3,4,3),plot (y, 'r')
title ('PD 3')
xlabel ('ISI #')
ylabel ('ISI (s)')
axis ([0,500,0.8,1.2])
disp ('PD 03 DONE')
y =Data.StrideTimeIntervals_15minTrial.PD(:,4);
subplot (3,4,4),plot (y, 'r')
title ('PD 4')
xlabel ('ISI #')
ylabel ('ISI (s)')
axis ([0,500,0.8,1.2])
disp ('PD 04 DONE')
y =Data.StrideTimeIntervals_15minTrial.PD(:,5);
subplot (3,4,5),plot (y, 'r')
title ('PD 5')
xlabel ('ISI #')
ylabel ('ISI (s)')
axis ([0,500,0.8,1.2])
disp ('PD 05 DONE')
y =Data.StrideTimeIntervals_15minTrial.PD(:,6);
subplot (3,4,6),plot (y, 'r')
title ('PD 6')
xlabel ('ISI #')
ylabel ('ISI (s)')
axis ([0,500,0.8,1.2])
disp ('PD 06 DONE')
y =Data.StrideTimeIntervals_15minTrial.PD(:,7);
subplot (3,4,7),plot (y, 'r')
title ('PD 7')
xlabel ('ISI #')
ylabel ('ISI (s)')
axis ([0,500,0.8,1.2])
disp ('PD 07 DONE')
y =Data.StrideTimeIntervals_15minTrial.PD(:,8);
subplot (3,4,8),plot (y, 'r')
title ('PD 8')
xlabel ('ISI #')
ylabel ('ISI (s)')
axis ([0,500,0.8,1.2])
disp ('PD 08 DONE')
y =Data.StrideTimeIntervals_15minTrial.PD(:,9);
subplot (3,4,9),plot (y, 'r')
title ('PD 9')
xlabel ('ISI #')
ylabel ('ISI (s)')
axis ([0,500,0.8,1.2])
disp ('PD 09 DONE')
y =Data.StrideTimeIntervals_15minTrial.PD(:,10);
subplot (3,4,10),plot (y, 'r')
title ('PD 10')
xlabel ('ISI #')
ylabel ('ISI (s)')
axis ([0,500,0.8,1.2])
disp ('PD 10 DONE')
y =Data.StrideTimeIntervals_15minTrial.PD(:,11);
subplot (3,4,11),plot (y, 'r')
title ('PD 11')
xlabel ('ISI #')
ylabel ('ISI (s)')
axis ([0,500,0.8,1.2])
disp ('PD 11 DONE')
y =Data.StrideTimeIntervals_15minTrial.PD(:,12);
subplot (3,4,12),plot (y, 'r')
title ('PD 12')
xlabel ('ISI #')
ylabel ('ISI (s)')
axis ([0,500,0.8,1.2])
disp ('PD 12 DONE')
0 Kommentare
Akzeptierte Antwort
the cyclist
am 3 Okt. 2019
Bearbeitet: the cyclist
am 3 Okt. 2019
In each subplot section ...
yline(mean(y),'g')
after you have defined the y value in that section, and done the plot.
Also, looks like you could make your code much more concise by using a for loop:
figure
for ii = 1:12
y =Data.StrideTimeIntervals_15minTrial.PD(:,ii);
subplot (3,4,ii),plot (y, 'r')
title (sprintf('PD %d',ii))
xlabel ('ISI #')
ylabel ('ISI (s)')
axis ([0,500,0.8,1.2])
disp (sprintf('PD %02d',ii))
end
5 Kommentare
the cyclist
am 3 Okt. 2019
Bearbeitet: the cyclist
am 3 Okt. 2019
figure
for ii = 1:12
% y =Data.StrideTimeIntervals_15minTrial.PD(:,ii);
y = 0.8 + 0.4*rand(1,500);
subplot (3,4,ii),plot (y, 'r')
h = yline(mean(y),'g');
set(h,'LineWidth',3)
title (sprintf('PD %d',ii))
xlabel ('ISI #')
ylabel ('ISI (s)')
axis ([0,500,0.8,1.2])
disp (sprintf('PD %02d',ii))
end
works for me.
Notice that I put in some random data in place of your code. So, the line is always going to be very close to the middle, since that is where the mean is.
Here, I made the line wider, too.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Labels and Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!