-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstdshade.m
More file actions
44 lines (33 loc) · 1.28 KB
/
stdshade.m
File metadata and controls
44 lines (33 loc) · 1.28 KB
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
37
38
39
40
41
42
43
44
function p = stdshade(amatrix,alpha,acolor,F,smth)
% usage: stdshading(amatrix,alpha,acolor,F,smth)
% plot mean and sem/std coming from a matrix of data, at which each row is an
% observation. sem/std is shown as shading.
% - acolor defines the used color (default is red)
% - F assignes the used x axis (default is steps of 1).
% - alpha defines transparency of the shading (default is no shading and black mean line)
% - smth defines the smoothing factor (default is no smooth)
% smusall 2010/4/23
if exist('acolor','var')==0 || isempty(acolor)
acolor='r';
end
if exist('F','var')==0 || isempty(F); F=1:size(amatrix,2);
end
if exist('smth','var'); if isempty(smth); smth=1; end
else
smth=1;
end
if ne(size(F,1),1)
F=F';
end
amean=smooth(nanmean(amatrix),smth)';
astd=nanstd(amatrix); % to get std shading
% astd=nanstd(amatrix)/sqrt(size(amatrix,1)); % to get sem shading
if exist('alpha','var')==0 || isempty(alpha)
fill([F fliplr(F)],[amean+astd fliplr(amean-astd)],acolor,'linestyle','none');
acolor='k';
else
fill([F fliplr(F)],[amean+astd fliplr(amean-astd)],acolor, 'FaceAlpha', alpha,'linestyle','none');
end
hold on;
p = plot(F,amean,'color',acolor,'linewidth',2); %% change color or linewidth to adjust mean line
end