1 function [D, M] = medAbsDev(X, DIM)
2 % medAbsDev calculates the median absolute deviation
4 % Usage: D = medAbsDev(X, DIM)
5 % or: [D, M] = medAbsDev(X, DIM)
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)
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/
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.
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.
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/>.
43 % median absolute deviation: median of absolute deviations to median
44 D = median(abs(X - repmat(M, size(X)./size(M))), DIM);