annotate scripts/general/runlength.m @ 8359:5798aa0f902a

[mq]: debug.patch
author jpswensen@john-swensens-macbook-pro-15.local
date Fri, 21 Nov 2008 22:53:50 -0500
parents fe2d956d9007
children 1bf0ce0930be
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7485
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
1 ## Copyright (C) 2005, 2008 Paul Kienzle
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
2 ##
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
3 ## This file is part of Octave.
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
4 ##
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
8 ## your option) any later version.
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
9 ##
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
13 ## General Public License for more details.
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
14 ##
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
18
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
19 ## -*- texinfo -*-
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
20 ## @deftypefn {Function File} {} runlength (@var{x})
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
21 ## Find the lengths of all sequences of common values. Return the
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
22 ## vector of lengths and the value that was repeated.
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
23 ##
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
24 ## @example
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
25 ## runlength ([2, 2, 0, 4, 4, 4, 0, 1, 1, 1, 1])
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
26 ## @result{} [2, 1, 3, 1, 4]
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
27 ## @end example
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
28 ## @end deftypefn
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
29
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
30 function [count, value] = runlength (x)
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
31 idx = [find(x(1:end-1) != x(2:end)), length(x)];
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
32 value = x(idx);
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
33 count = diff ([0 idx]);
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
34 endfunction
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
35
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
36 %!assert (runlength([2 2 0 4 4 4 0 1 1 1 1]), [2 1 3 1 4]);