Mercurial > hg > octave-lyh
diff scripts/statistics/base/ranks.m @ 4886:54b076a24718
[project @ 2004-04-30 04:31:51 by jwe]
author | jwe |
---|---|
date | Fri, 30 Apr 2004 04:31:51 +0000 |
parents | 28ab079d8f0e |
children | a0f2839f6ac8 |
line wrap: on
line diff
--- a/scripts/statistics/base/ranks.m +++ b/scripts/statistics/base/ranks.m @@ -43,32 +43,33 @@ nd = ndims (x); sz = size (x); if (nargin != 2) - %% Find the first non-singleton dimension + ## Find the first non-singleton dimension. dim = 1; - while (dim < nd + 1 && sz (dim) == 1) + while (dim < nd + 1 && sz(dim) == 1) dim = dim + 1; endwhile if (dim > nd) dim = 1; endif else - if (! (isscalar (dim) && dim == round (dim)) && dim > 0 && - dim < (nd + 1)) + if (! (isscalar (dim) && dim == round (dim)) + && dim > 0 + && dim < (nd + 1)) error ("ranks: dim must be an integer and valid dimension"); endif endif - if (sz (dim) == 1) + if (sz(dim) == 1) y = ones(sz); else ## The algorithm works only on dim=1, so permute if necesary if (dim != 1) perm = [1 : nd]; - perm (1) = dim; - perm (dim) = 1; + perm(1) = dim; + perm(dim) = 1; x = permute (x, perm); endif - sz = size (x); + sz = size (x); infvec = -Inf * ones ([1, sz(2 : end)]); [xs, y] = sort (x); eq_el = find (diff ([xs; infvec]) == 0); @@ -76,14 +77,13 @@ [eq_el, y] = sort (y); else runs = complement (eq_el+1, eq_el); - runs = reshape (y (runs), size (runs)) + - floor (runs ./ sz (1)) * sz(1); + runs = reshape (y (runs), size (runs)) + floor (runs ./ sz(1)) * sz(1); len = diff (find (diff ([Inf; eq_el; -Inf]) != 1)) + 1; - [eq_el, y] = sort (y); + [eq_el, y] = sort (y); for i = 1 : length(runs) - p = y (runs (i)) + (len (i) - 1) / 2; - for j = 0 : len (i) - 1 - y (runs (i) + j) = p; + p = y(runs(i)) + (len(i) - 1) / 2; + for j = 0 : len(i) - 1 + y(runs(i) + j) = p; endfor endfor endif