-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshade_plot.m
36 lines (27 loc) · 1.11 KB
/
shade_plot.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function p = shade_plot(x, y, lineStyle, linewidth, shade_color)
%****************Assumptions***************
%x dimension = samples * 1 (sample = any quantity that forms x axis)
%y dimension = samples * trials (trials can be anything else on which you
% want to average, and also calculate shades
%lineStyle is a string like ':' or '--'
%shade_color is a string like 'blue'
%***************************************************
if size(x,1) == 1
x = x.'; %Transposing x if it is given as a row vector
end
mean_y = squeeze(mean(y, 2));
std_y = squeeze(std(y, [] , 2));
n = size(y, 2);
xBetween=[x; flipud(x)];
% disp(size(xBetween,1));
% disp(size(xBetween,2));
lowShade = mean_y - std_y / sqrt(n);
upShade = mean_y + std_y / sqrt(n);
yBetween = [lowShade; flipud(upShade)];
% disp(size(yBetween,1));
% disp(size(yBetween,2));
p = plot(x, mean_y, lineStyle, 'Linewidth', linewidth);
hold on;
fill(xBetween, yBetween, shade_color,'LineStyle','none','FaceAlpha',0.1, ...
'handlevisibility','off');
end