3200
|
1 ## Copyright (C) 1995, 1996, 1997 Kurt Hornik |
3426
|
2 ## |
3922
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
3200
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
3426
|
9 ## |
3922
|
10 ## Octave is distributed in the hope that it will be useful, but |
3200
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3426
|
13 ## General Public License for more details. |
|
14 ## |
3200
|
15 ## You should have received a copy of the GNU General Public License |
3922
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, USA. |
3200
|
19 |
3453
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} ranks (@var{x}) |
|
22 ## If @var{x} is a vector, return the (column) vector of ranks of |
|
23 ## @var{x} adjusted for ties. |
3200
|
24 ## |
3453
|
25 ## If @var{x} is a matrix, do the above for each column of @var{x}. |
|
26 ## @end deftypefn |
3426
|
27 |
3456
|
28 ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> |
|
29 ## Description: Compute ranks |
3200
|
30 |
|
31 ## This code is rather ugly, but is there an easy way to get the ranks |
|
32 ## adjusted for ties from sort? |
3426
|
33 |
3200
|
34 function y = ranks (x) |
|
35 |
|
36 if (nargin != 1) |
|
37 usage ("ranks (x)"); |
|
38 endif |
3426
|
39 |
3200
|
40 y = []; |
|
41 |
|
42 [r, c] = size (x); |
|
43 if ((r == 1) && (c > 0)) |
|
44 p = x' * ones (1, c); |
|
45 y = sum (p < p') + (sum (p == p') + 1) / 2; |
|
46 elseif (r > 1) |
|
47 o = ones (1, r); |
|
48 for i = 1 : c; |
|
49 p = x (:, i) * o; |
3457
|
50 y = [y, (sum (p < p') + (sum (p == p') + 1) / 2)']; |
3200
|
51 endfor |
|
52 endif |
3426
|
53 |
3200
|
54 endfunction |