]> Creatis software - CreaPhase.git/blob - octave_packages/nan-2.5.5/center.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nan-2.5.5 / center.m
1 function [i,S] = center(i,DIM,W)
2 % CENTER removes the mean 
3 %
4 % [z,mu] = center(x,DIM,W)
5 %   removes mean x along dimension DIM
6 %
7 % x     input data 
8 % DIM   dimension
9 %       1: column
10 %       2: row
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)
14 %
15 % features:
16 % - can deal with NaN's (missing values)
17 % - weighting of data 
18 % - dimension argument 
19 % - compatible to Matlab and Octave
20 %
21 % see also: SUMSKIPNAN, MEAN, STD, DETREND, ZSCORE
22 %
23 % REFERENCE(S):
24
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.
29 %
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.
34 %
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/>.
37
38
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/
43
44
45 if any(size(i)==0); return; end;
46
47 if nargin<3,
48         W = [];
49 end; 
50 if nargin>1,
51         [S,N] = sumskipnan(i,DIM,W);
52 else
53         [S,N] = sumskipnan(i,[],W);
54 end;
55
56 S     = S./N;
57 szi = size(i);
58 szs = size(S);
59 if length(szs)<length(szi);
60         szs(length(szs)+1:length(szi)) = 1;
61 end;
62 i = i - repmat(S,szi./szs);             % remove mean