home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts.fat / stat / base / run_cnt.m < prev    next >
Text File  |  1999-04-29  |  1KB  |  58 lines

  1. ## Copyright (C) 1995, 1996, 1997  Friedrich Leisch
  2. ## 
  3. ## This program is free software; you can redistribute it and/or modify
  4. ## it under the terms of the GNU General Public License as published by
  5. ## the Free Software Foundation; either version 2, or (at your option)
  6. ## any later version.
  7. ## 
  8. ## This program is distributed in the hope that it will be useful, but
  9. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11. ## General Public License for more details. 
  12. ## 
  13. ## You should have received a copy of the GNU General Public License
  14. ## along with this file.  If not, write to the Free Software Foundation,
  15. ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16.  
  17. ## usage:  run_cnt (x, n)
  18. ##
  19. ## Counts the upward runs in the columns of x of length 1, 2, ... n-1
  20. ## and >= n.
  21.  
  22. ## Author:  FL <Friedrich.Leisch@ci.tuwien.ac.at>
  23. ## Description:  Count upward runs
  24.  
  25. function retval = run_cnt (x, n)
  26.   
  27.   [xr, xc] = size(x);
  28.   
  29.   tmp = zeros (xr,xc);
  30.   retval = zeros (n, xc);
  31.   
  32.   for j = 1 : xc
  33.     run = 1;
  34.     count = 1;
  35.  
  36.     for k = 2 : xr
  37.  
  38.       if x(k, j) < x(k-1, j)
  39.     tmp(run, j) = count;
  40.     run = run + 1;
  41.     count = 0;
  42.       endif
  43.     
  44.       count = count + 1;
  45.  
  46.     endfor
  47.  
  48.     tmp(run, j) = count;
  49.   
  50.   endfor
  51.   
  52.   for k=1 : (n-1)
  53.     retval(k, :) = sum (tmp == k);
  54.   endfor
  55.   retval(n, :) = sum (tmp >= n);
  56.   
  57. endfunction
  58.