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