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-
You can solve this as a string search task, by finding strings of zeros of length thresh (STRFIND function is very fast)
startIndex = strfind(sig, zeros(1,thresh));
Note that longer substrings will get marked in multiple locations but will eventually be joined once we add in-between locations from intervals start at startIndex to end at start+thresh-1.
indices = unique( bsxfun(@plus, startIndex', 0:thresh-1) )';
Note that you can always swap this last step with the CUMSUM/FIND solution by @gnovice from the linked question.