0001 function str = mean2str(m,s,n,varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 precision = 3;
0031 split = 'off';
0032
0033
0034 if nargin < 2,
0035 error('Incorrect number of parameters (type ''help <a href="matlab:help mean2str">mean2str</a>'' for details).');
0036 end
0037 if ~isdscalar(m),
0038 error('Incorrect mean or median (type ''help <a href="matlab:help mean2str">mean2str</a>'' for details).');
0039 end
0040 if ~isdscalar(s) && ~isdvector(s,'<=','#2'),
0041 error('Incorrect SEM or confidence interval (type ''help <a href="matlab:help mean2str">mean2str</a>'' for details).');
0042 end
0043
0044
0045 if nargin < 3,
0046 n = [];
0047 elseif ischar(n),
0048 varargin = {n,varargin{:}};
0049 n = [];
0050 elseif ~isiscalar(n,'>0'),
0051 error('Incorrect number of observations (type ''help <a href="matlab:help mean2str">mean2str</a>'' for details).');
0052 end
0053
0054
0055 for i = 1:2:length(varargin),
0056 if ~ischar(varargin{i}),
0057 error(['Parameter ' num2str(i+2) ' is not a property (type ''help <a href="matlab:help mean2str">mean2str</a>'' for details).']);
0058 end
0059 switch(lower(varargin{i})),
0060 case 'precision',
0061 precision = varargin{i+1};
0062 if ~isiscalar(precision,'>0'),
0063 error('Incorrect value for property ''precision'' (type ''help <a href="matlab:help mean2str">mean2str</a>'' for details).');
0064 end
0065 case 'split',
0066 split = lower(varargin{i+1});
0067 if ~isastring(split,'on','off'),
0068 error('Incorrect value for property ''split'' (type ''help <a href="matlab:help mean2str">mean2str</a>'' for details).');
0069 end
0070 otherwise,
0071 error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help mean2str">mean2str</a>'' for details).']);
0072 end
0073 end
0074
0075 format = ['%.' int2str(precision) 'f'];
0076 if isdscalar(s),
0077 str = [sprintf(format,m) ' +- ' sprintf(format,s)];
0078 else
0079 str = [sprintf(format,m) ' [' sprintf(format,s(1)) ',' sprintf(format,s(2)) ']'];
0080 end
0081 if ~isempty(n),
0082 if strcmp(split,'on'),
0083 str = {str,['(N=' int2str(n) ')']};
0084 else
0085 str = [str ' (N=' int2str(n) ')'];
0086 end
0087 end