X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=octave_packages%2Fnan-2.5.5%2Ftrimean.m;fp=octave_packages%2Fnan-2.5.5%2Ftrimean.m;h=fe910fd055ae08c99f792c3c06f359f21129dbe0;hb=c880e8788dfc484bf23ce13fa2787f2c6bca4863;hp=0000000000000000000000000000000000000000;hpb=1705066eceaaea976f010f669ce8e972f3734b05;p=CreaPhase.git diff --git a/octave_packages/nan-2.5.5/trimean.m b/octave_packages/nan-2.5.5/trimean.m new file mode 100644 index 0000000..fe910fd --- /dev/null +++ b/octave_packages/nan-2.5.5/trimean.m @@ -0,0 +1,79 @@ +function y=trimean(x,DIM) +% TRIMEAN yields the weighted mean of the median and the quartiles +% m = TRIMEAN(y). +% +% The trimean is m = (Q1+2*MED+Q3)/4 +% with quartile Q1 and Q3 and median MED +% +% N-dimensional data is supported +% +% REFERENCES: +% [1] http://mathworld.wolfram.com/Trimean.html + + +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; If not, see . + +% $Id: trimean.m 9601 2012-02-09 14:14:36Z schloegl $ +% Copyright (C) 1996-2003,2009,2010 by Alois Schloegl +% This function is part of the NaN-toolbox +% http://pub.ist.ac.at/~schloegl/matlab/NaN/ + +global FLAG_NANS_OCCURED; + +% check dimension +sz=size(x); + +% find the dimension +if nargin==1, + DIM = find(size(x)>1,1); + if isempty(DIM), DIM=1; end; +end; + +if DIM>length(sz), + sz = [sz,ones(1,DIM-length(sz))]; +end; + +D1 = prod(sz(1:DIM-1)); +D2 = sz(DIM); +D3 = prod(sz(DIM+1:length(sz))); +D0 = [sz(1:DIM-1),1,sz(DIM+1:length(sz))]; +y = repmat(nan,D0); +q = repmat(nan,3,1); +for k = 0:D1-1, +for l = 0:D3-1, + xi = k + l * D1*sz(DIM) + 1 ; + xo = k + l * D1 + 1; + t = x(xi+(0:sz(DIM)-1)*D1); + t = sort(t(~isnan(t))); + t = t(:); + n = length(t); + if (n