-
Notifications
You must be signed in to change notification settings - Fork 0
/
Error_bars_multibar.m
93 lines (86 loc) · 2.25 KB
/
Error_bars_multibar.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
function [hb ,he]= Error_bars_multibar(varargin)
%[e,m,err] =
%function Error_bars(varargin)
% Plot a bar graph of the matrices in varargin of their means and sem and stds.
% INPUT : varargin of vectors for calculating means and stds and sems on
% assumes that all vargins only one column.
% OUTPUT: Bar graph with the SEM as a red error whisker.
% reference to the handle of the error bars
% cowen
error_type = 'Sem';
plot_points = true;
count = 1;
% find commands and creat an argument cell array that just has the data.
for ii = 1:length(varargin)
if ischar(varargin{ii})
switch varargin{ii}
case 'std'
error_type = 'std';
case 'nanstd'
error_type = 'nanstd';
case '1.95*std'
error_type = '1.95*std';
otherwise
error('Incorrect error type')
end
else
arg{count} = varargin{ii};
count = count + 1;
end
end
%%%%%% the real code %%%%%
if length(arg) == 1
if iscell(arg{1})
error('hmmm')
else
m = nanmean(arg{1});
sd = nanstd(arg{1});
eval(['err = ' error_type '(arg{1});']);
end
else
%m = zeros(size(arg{1},2),length(arg));
%sd = zeros(size(arg{1},2),length(arg));
%err = zeros(size(arg{1},2),length(arg));
for ii = 1:length(arg)
if isempty(arg{ii})
arg{ii} = nan;
end
m(ii) = nanmean(arg{ii});
sd(ii) = nanstd(arg{ii});
eval(['err(ii) = ' error_type '(arg{ii});']);
err(ii) = feval(error_type,arg{ii});
end
end
hh = bar(m);
set(hh,'FaceColor',[.8 .8 .8])
hold on
if plot_points
for iarg=1:length(arg)
for ii = 1:Cols(arg{iarg})
pts = arg{iarg}(:,ii);
x = repmat(ii,length(pts),iarg);
x = x + (rand(size(x))-.5)*.2;
plot(x,pts,'.b','MarkerSize',16)
end
end
end
%errorbar(m,sd,'+')
if 1
errorb(1:length(m),m,err,'barwidth',2); e = [];
else
e = errorbar(m,err,'k','LineStyle','none');
end
hold on
% set(e,'LineWidth',2)
% set(gca,'FontSize',12)
%set(e,'MarkerSize',0.1)
%hold on
%plot(m,'+k')
%set(e(2),'MarkerSize',.1);
%set(e(2),'Color','b');
%hold off
pubify_figure_axis
if nargout > 0
hb = hh;
he = e;
end