[8406bc]: / MATLAB / src / meanStats.m

Download this file

30 lines (26 with data), 928 Bytes

 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
function statsCell = meanStats(data, varargin)
%MEANSTATS calculates mean statistics.
%
% AUTHOR: Maximilian C. M. Fischer
% COPYRIGHT (C) 2022-2023 Maximilian C. M. Fischer
% LICENSE: EUPL v1.2
%
p = inputParser;
addRequired(p,'data',@(x) validateattributes(x,{'numeric'},{'ncols', 1}))
addParameter(p,'format', 'long',@(x) any(validatestring(x,{'long','short'})));
addOptional(p,'fSpec', '% 1.1f',@ischar);
parse(p,data,varargin{:});
fSpec = p.Results.fSpec;
format = p.Results.format;
MEAN=nanmean(data);
STD(1)=nanstd(data);STD(2)=MEAN-STD(1);STD(3)=MEAN+STD(1);
RNG(1)=range(data);RNG(2)=min(data);RNG(3)=max(data);
switch format
case 'long'
statsCell = {[...
num2str(MEAN,fSpec) ' (' num2str(STD(1),fSpec) ', ' ...
num2str(RNG(2),fSpec) ' to ' num2str(RNG(3),fSpec) ')']};
case 'short'
statsCell = {[num2str(MEAN,fSpec) ' ' char(177) ' ' num2str(STD(1),fSpec)]};
end
end