help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: a function for computing bursts of errors


From: Stefan van der Walt
Subject: Re: a function for computing bursts of errors
Date: Wed, 2 Mar 2005 03:06:37 +0200
User-agent: Mutt/1.5.6+20040907i

Hi Francesco

There is a good old American (?) saying:

"If it ain't broke don't fix it"

Unless you have specific problems (maybe you have HUGE vectors and
want to minimise memory usage), I don't see the need to change
anything.

As for memory usage:

octave:8> x = ones(1000);
octave:9> y = logical(x);
octave:10> whos

...

*** local user variables:

  Prot Name            Size                     Bytes  Class
  ==== ====            ====                     =====  =====
   rwd x            1000x1000                 8000000  matrix
   rwd y            1000x1000                 1000000  bool matrix


Regards
Stefan

On Tue, Mar 01, 2005 at 09:20:57AM +0100, Francesco Potorti` wrote:
> 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
> ============================================================



-------------------------------------------------------------
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
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]