]> Creatis software - CreaPhase.git/blob - octave_packages/nan-2.5.5/zScoreMedian.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nan-2.5.5 / zScoreMedian.m
1 function Z = zScoreMedian(X, DIM)
2 % zScoreMedian removes the median and standardizes by the 1.483*median absolute deviation
3 %
4 % Usage:  Z = zScoreMedian(X, DIM)
5 % Input:  X  : data
6 %         DIM: dimension along which z-score should be calculated (1=columns, 2=rows) 
7 %              (optional, default=first dimension with more than 1 element
8 % Output: Z  : z-scores
9
10 %       Copyright (C) 2003 Patrick Houweling
11 %       Copyright (C) 2009 Alois Schloegl
12 %       $Id: zScoreMedian.m 8075 2011-01-27 17:10:36Z schloegl $
13 %       This function is part of the NaN-toolbox
14 %       http://pub.ist.ac.at/~schloegl/matlab/NaN/
15
16 %    This program is free software: you can redistribute it and/or modify
17 %    it under the terms of the GNU General Public License as published by
18 %    the Free Software Foundation, either version 3 of the License, or
19 %    (at your option) any later version.
20 %
21 %    This program is distributed in the hope that it will be useful,
22 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
23 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 %    GNU General Public License for more details.
25 %
26 %    You should have received a copy of the GNU General Public License
27 %    along with this program.  If not, see <http://www.gnu.org/licenses/>.
28
29
30 % input checks
31 if any(size(X)==0), 
32         return; 
33 end;
34
35 % robust moment estimators: 
36 % - mean: median
37 % - standard deviation: 1.483 * median absolute deviation (medAbsDev);
38 %   the factor 1.483 is the ratio of the standard deviation of a normal random variable to its MAD.
39 if nargin<2,
40         [D, M] = medAbsDev(X);
41 else
42         [D, M] = medAbsDev(X, DIM);
43 end;
44
45 % z-score: subtract M and divide by 1.483*D
46 Z = (X - repmat(M, size(X)./size(M))) ./ repmat(1.483*D, size(X)./size(D));