annotate scripts/general/runlength.m @ 11188:4cb1522e4d0f

Use function handle as input to cellfun, rather than quoted function name or anonymous function wrapper.
author Rik <octave@nomad.inbox5.com>
date Wed, 03 Nov 2010 17:20:56 -0700
parents 16f53d29049f
children fd0a3ac60b0e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9245
16f53d29049f update copyright notices
John W. Eaton <jwe@octave.org>
parents: 9051
diff changeset
1 ## Copyright (C) 2005, 2008, 2009 Paul Kienzle
7485
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
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 7485
diff changeset
25 ## @group
7485
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
26 ## runlength ([2, 2, 0, 4, 4, 4, 0, 1, 1, 1, 1])
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
27 ## @result{} [2, 1, 3, 1, 4]
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 7485
diff changeset
28 ## @end group
7485
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
29 ## @end example
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
30 ## @end deftypefn
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
31
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
32 function [count, value] = runlength (x)
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
33 idx = [find(x(1:end-1) != x(2:end)), length(x)];
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
34 value = x(idx);
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
35 count = diff ([0 idx]);
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
36 endfunction
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
37
fe2d956d9007 handle ties in kruskal_wallis_test
Timo Lindfors
parents:
diff changeset
38 %!assert (runlength([2 2 0 4 4 4 0 1 1 1 1]), [2 1 3 1 4]);