Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>These are the steps I would take to solve your problem in a vectorized way, starting with a given vector <code>sig</code>:</p> <ul> <li><p>First, threshold the vector to get a vector <code>tsig</code> of zeros and ones (zeroes where the absolute value of the signal drops close enough to zero, ones elsewhere):</p> <pre><code>tsig = (abs(sig) &gt;= eps); %# Using eps as the threshold </code></pre></li> <li><p>Next, find the starting indices, ending indices, and duration of each string of zeroes using the functions <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/diff.html" rel="nofollow noreferrer">DIFF</a> and <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/find.html" rel="nofollow noreferrer">FIND</a>:</p> <pre><code>dsig = diff([1 tsig 1]); startIndex = find(dsig &lt; 0); endIndex = find(dsig &gt; 0)-1; duration = endIndex-startIndex+1; </code></pre></li> <li><p>Then, find the strings of zeroes with a duration greater than or equal to some value (such as 3, from your example):</p> <pre><code>stringIndex = (duration &gt;= 3); startIndex = startIndex(stringIndex); endIndex = endIndex(stringIndex); </code></pre></li> <li><p>Finally, use <a href="https://stackoverflow.com/questions/2807270/matlab-vectorized-array-creation-from-a-list-of-start-end-indices/2807994#2807994">the method from my answer to the linked question</a> to generate your final set of indices:</p> <pre><code>indices = zeros(1,max(endIndex)+1); indices(startIndex) = 1; indices(endIndex+1) = indices(endIndex+1)-1; indices = find(cumsum(indices)); </code></pre></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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