[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
a function for computing bursts of errors
From: |
Francesco Potorti` |
Subject: |
a function for computing bursts of errors |
Date: |
Tue, 01 Mar 2005 09:20:57 +0100 |
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?
===File /home/pot/math/octavelib/tsa/bursts.m===============
function b = bursts(x)
## usage: B = 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ì <address@hidden>, 2004
## License: GNU GPL <http://www.gnu.org/licenses/gpl.html>
if (nargin != 1)
usage ("B = 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) != 1)
x = x';
endif
x = !x;
## Find the places where there is a 1, then compute the burst lenghts.
b = diff([0;find(x);rows(x)+1])-1;
## Remove the zero-length bursts
b = b(b>0);
endfunction
============================================================
--
Francesco Potortì (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: address@hidden
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
-------------------------------------------------------------
- a function for computing bursts of errors,
Francesco Potorti` <=