a function for computing bursts of errors
Francesco Potorti` <[email protected]> Tue, 01 Mar 2005 09:20:57 +0100
| Newsgroups | gmane.comp.gnu.octave.general,gmane.comp.gnu.octave.sources |
|---|---|
| Organization | ISTI-CNR, via Moruzzi 1, I-56124 Pisa, +39-0503153058 |
| Message-ID | <[email protected]> |
Say I have a list of 1's and 0's, each 1 representing a rare event (an error), each 0 representing a normal event (no error). I want to compute the distribution of error burst lengths. This function makes an array where each element, one per error burst, contains the burst length. Now that I discovered about bool values, is there a way that I could take advantage of boolean arrays in this function? =3D=3D=3DFile /home/pot/math/octavelib/tsa/bursts.m=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D function b =3D bursts(x) ## usage: B =3D bursts (X) ## ## Given a matrix X, return the number of bursts of different lengths. ## ## A burst of length n is a sequence of n values different from 0, ## delimited either by zero values or the start or end of the vector. ## ## Francesco Potort=EC <[email protected]>, 2004 ## License: GNU GPL <http://www.gnu.org/licenses/gpl.html> if (nargin !=3D 1) usage ("B =3D bursts (X)"); endif if (!isvector(x)) error ("bursts: x must be a vector"); endif ## Make x a column vector of ones where different from 0. if (columns(x) !=3D 1) x =3D x'; endif x =3D !x; ## Find the places where there is a 1, then compute the burst lenghts. b =3D diff([0;find(x);rows(x)+1])-1; ## Remove the zero-length bursts b =3D b(b>0); endfunction =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --=20 Francesco Potort=EC (ricercatore) Voice: +39 050 315 3058 (op.2111= ) ISTI - Area della ricerca CNR Fax: +39 050 313 8091 via G. Moruzzi 1, I-56124 Pisa Email: [email protected] Web: http://fly.isti.cnr.it/ Key: fly.isti.cnr.it/public.key ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------