1 function [SE,M]=sem(x,DIM, W)
2 % SEM calculates the standard error of the mean
4 % [SE,M] = SEM(x [, DIM [,W]])
5 % calculates the standard error (SE) in dimension DIM
6 % the default DIM is the first non-single dimension
8 % Can deal with complex data, too.
13 % N: SEM of N-th dimension
14 % default or []: first DIMENSION, with more than 1 element
15 % W weights to compute weighted mean and s.d. (default: [])
16 % if W=[], all weights are 1.
17 % number of elements in W must match size(x,DIM)
20 % - can deal with NaN's (missing values)
22 % - dimension argument
23 % - compatible to Matlab and Octave
25 % see also: SUMSKIPNAN, MEAN, VAR, STD
27 % This program is free software; you can redistribute it and/or modify
28 % it under the terms of the GNU General Public License as published by
29 % the Free Software Foundation; either version 3 of the License, or
30 % (at your option) any later version.
32 % This program is distributed in the hope that it will be useful,
33 % but WITHOUT ANY WARRANTY; without even the implied warranty of
34 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 % GNU General Public License for more details.
37 % You should have received a copy of the GNU General Public License
38 % along with this program; If not, see <http://www.gnu.org/licenses/>.
40 % Copyright (C) 2000-2003,2008,2009 by Alois Schloegl <alois.schloegl@gmail.com>
41 % $Id: sem.m 8223 2011-04-20 09:16:06Z schloegl $
42 % This function is part of the NaN-toolbox
43 % http://pub.ist.ac.at/~schloegl/matlab/NaN/
47 [S,N,SSQ] = sumskipnan(x,DIM,W);
49 [S,N,SSQ] = sumskipnan(x,DIM);
51 [S,N,SSQ] = sumskipnan(x);
55 SE = (SSQ.*N - real(S).^2 - imag(S).^2)./(N.*N.*(N-1));
56 SE(SE<=0) = 0; % prevent negative value caused by round-off error