Note that there are some explanatory texts on larger screens.

plurals
  1. POFinding islands of zeros in a sequence
    primarykey
    data
    text
    <p>Imagine you have a very long sequence. What is the most efficient way of finding the intervals where the sequence is all zeros (or more precisely the sequence drops to near-zero values <code>abs(X)&lt;eps</code>):</p> <p>For simplicity, lets assume the following sequence:</p> <pre><code>sig = [1 1 0 0 0 0 1 1 1 1 1 0 1 0 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 0]; </code></pre> <p>I'm trying to get the following information:</p> <pre><code>startIndex EndIndex Duration 3 6 4 12 12 1 14 16 3 25 26 2 30 30 1 </code></pre> <p>then using this information, we find the intervals with duration >= to some specified value (say <code>3</code>), and returning the indices of the values in all these intervals combined:</p> <pre><code>indices = [3 4 5 6 14 15 16]; </code></pre> <p>That last part is related to a previous question:</p> <blockquote> <p><a href="https://stackoverflow.com/questions/2807270/matlab-vectorized-array-creation-from-a-list-of-start-end-indices">MATLAB: vectorized array creation from a list of start/end indices</a></p> </blockquote> <p>This is what I have so far:</p> <pre><code>sig = [1 1 0 0 0 0 1 1 1 1 1 0 1 0 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 0]; len = length(sig); thresh = 3; %# align the signal with itself successively shifted by one %# v will thus contain 1 in the starting locations of the zero interval v = true(1,len-thresh+1); for i=1:thresh v = v &amp; ( sig(i:len-thresh+i) == 0 ); end %# extend the 1's till the end of the intervals for i=1:thresh-1 v(find(v)+1) = true; end %# get the final indices v = find(v); </code></pre> <p>I'm looking to vectorize/optimize the code, but I'm open to other solutions. I have to stress that space and time efficiencies are very important, since I'm processing a large number of long bio-signals.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload