-
Notifications
You must be signed in to change notification settings - Fork 0
/
writeMeanNSem.m
36 lines (28 loc) · 1.01 KB
/
writeMeanNSem.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
function [ ] = writeMeanNSem( y_values,shift,x_position,text_varargin,isbottom )
% writeMeanNSem( y_values,shift,x_position,text_varargin )
% Write the value of the mean plus minus 95% CI
if nargin<4||isempty(text_varargin)
text_varargin = {};
end
% We assume that using univarscatter, the x positions are 1:size(y_values,2)
if nargin<3||isempty(x_position)
x_text = 1:size(y_values,2);
end
if nargin<5||isempty(isbottom)
isbottom=true;
end
if isbottom
y_text = min(y_values)-shift;
else
y_text = max(y_values)+shift;
end
all_mean = nanmean(y_values);
all_std = nanstd(y_values);
all_nb_obs = nansum(~isnan(y_values));
all_95CI = 1.96*all_std./sqrt(all_nb_obs);
for i = 1:size(y_values,2)
text_value = sprintf('%.2f \\pm %.2f',all_mean(i),all_95CI(i));
text(x_text(i),y_text(i),text_value,'HorizontalAlignment','Center',text_varargin{:});
[x_text(i),y_text(i)]
end
end