1 function [i,S] = center(i,DIM,W)
2 % CENTER removes the mean
4 % [z,mu] = center(x,DIM,W)
5 % removes mean x along dimension DIM
11 % default or []: first DIMENSION, with more than 1 element
12 % W weights to computed weighted mean (default: [], all weights = 1)
13 % numel(W) must be equal to size(x,DIM)
16 % - can deal with NaN's (missing values)
18 % - dimension argument
19 % - compatible to Matlab and Octave
21 % see also: SUMSKIPNAN, MEAN, STD, DETREND, ZSCORE
25 % This program is free software; you can redistribute it and/or modify
26 % it under the terms of the GNU General Public License as published by
27 % the Free Software Foundation; either version 2 of the License, or
28 % (at your option) any later version.
30 % This program is distributed in the hope that it will be useful,
31 % but WITHOUT ANY WARRANTY; without even the implied warranty of
32 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 % GNU General Public License for more details.
35 % You should have received a copy of the GNU General Public License
36 % along with this program; If not, see <http://www.gnu.org/licenses/>.
39 % $Id: center.m 8223 2011-04-20 09:16:06Z schloegl $
40 % Copyright (C) 2000-2003,2005,2009 by Alois Schloegl <alois.schloegl@gmail.com>
41 % This is part of the NaN-toolbox. For more details see
42 % http://pub.ist.ac.at/~schloegl/matlab/NaN/
45 if any(size(i)==0); return; end;
51 [S,N] = sumskipnan(i,DIM,W);
53 [S,N] = sumskipnan(i,[],W);
59 if length(szs)<length(szi);
60 szs(length(szs)+1:length(szi)) = 1;
62 i = i - repmat(S,szi./szs); % remove mean