3200
|
1 ## Copyright (C) 1995, 1996, 1997 Friedrich Leisch |
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} {} run_count (@var{x}, @var{n}) |
|
22 ## Count the upward runs in the columns of @var{x} of length 1, 2, ..., |
|
23 ## @var{n}-1 and greater than or equal to @var{n}. |
|
24 ## @end deftypefn |
3200
|
25 |
3456
|
26 ## Author: FL <Friedrich.Leisch@ci.tuwien.ac.at> |
|
27 ## Description: Count upward runs |
3200
|
28 |
|
29 function retval = run_count (x, n) |
3426
|
30 |
3200
|
31 [xr, xc] = size(x); |
3426
|
32 |
3200
|
33 tmp = zeros (xr,xc); |
|
34 retval = zeros (n, xc); |
3426
|
35 |
3200
|
36 for j = 1 : xc |
|
37 run = 1; |
|
38 count = 1; |
|
39 |
|
40 for k = 2 : xr |
|
41 |
|
42 if x(k, j) < x(k-1, j) |
3426
|
43 tmp(run, j) = count; |
|
44 run = run + 1; |
|
45 count = 0; |
3200
|
46 endif |
3426
|
47 |
3200
|
48 count = count + 1; |
|
49 |
|
50 endfor |
|
51 |
|
52 tmp(run, j) = count; |
3426
|
53 |
3200
|
54 endfor |
3426
|
55 |
3200
|
56 for k=1 : (n-1) |
|
57 retval(k, :) = sum (tmp == k); |
|
58 endfor |
|
59 retval(n, :) = sum (tmp >= n); |
3426
|
60 |
3200
|
61 endfunction |