Home > FMAToolbox > General > mean2str.m

mean2str

PURPOSE ^

mean2str - Convert mean or median and SEM (or confidence interval) to string.

SYNOPSIS ^

function str = mean2str(m,s,n,varargin)

DESCRIPTION ^

mean2str - Convert mean or median and SEM (or confidence interval) to string.

  USAGE

    s = mean2str(m,s,n,<options>)

    m              mean or median
    s              standard error (see <a href="matlab:help sem">sem</a> or <a href="matlab:help semedian">semedian</a>) or confidence interval
    n              optional number of observations
    <options>      optional list of property-value pairs (see table below)

    =========================================================================
     Properties    Values
    -------------------------------------------------------------------------
     'precision'   number of digits (default = 3)
     'split'       split the output in two cells, e.g. for small figures
                   (default = 'off')
    =========================================================================

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function str = mean2str(m,s,n,varargin)
0002 
0003 %mean2str - Convert mean or median and SEM (or confidence interval) to string.
0004 %
0005 %  USAGE
0006 %
0007 %    s = mean2str(m,s,n,<options>)
0008 %
0009 %    m              mean or median
0010 %    s              standard error (see <a href="matlab:help sem">sem</a> or <a href="matlab:help semedian">semedian</a>) or confidence interval
0011 %    n              optional number of observations
0012 %    <options>      optional list of property-value pairs (see table below)
0013 %
0014 %    =========================================================================
0015 %     Properties    Values
0016 %    -------------------------------------------------------------------------
0017 %     'precision'   number of digits (default = 3)
0018 %     'split'       split the output in two cells, e.g. for small figures
0019 %                   (default = 'off')
0020 %    =========================================================================
0021 
0022 % Copyright (C) 2013 by Michaƫl Zugaro
0023 %
0024 % This program is free software; you can redistribute it and/or modify
0025 % it under the terms of the GNU General Public License as published by
0026 % the Free Software Foundation; either version 3 of the License, or
0027 % (at your option) any later version.
0028 
0029 % Default values
0030 precision = 3;
0031 split = 'off';
0032 
0033 % Check parameters
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 % Optional number of observations
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 % Parse parameter list
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

Generated on Fri 16-Mar-2018 13:00:20 by m2html © 2005