arrays - Find indices of blocks of 0s that are continuous -


this question has answer here:

i have vector , want find indices of blocks of 0s continuous @ least 3 times.

y = [1 1 1 0 1 1 0 0 0 1 1 1 0 1 0 1 0 0 1 0 0 0 0 1 1]; 

so in case, blocks should [0 0 0] 7-9 , [0 0 0 0] 20-23. output should give me indices, [7, 9] , [20,23], or better, change these blocks of 0s single nan become:

[1 1 1 0 1 1 nan 1 1 1 0 1 0 1 0 0 1 nan 1 1]     

thanks!

what can is:

  1. pad vector 1 on each side.
  2. use find , diff find vector changes 1 0 (diff = -1)
  3. use find , diff find vector changes 0 1 (diff = 1)
  4. find duration of each interval subtracting values in 3 values in 2 (and add 1)
  5. create logical vector true duration >= 3, , use vector find start indices (from values found in point 2).
  6. set value of each of start indices nan
  7. set value of start indices + 1 : end indices [].

and you're set go!

it took lot more time writing explanation took write code. it's quite nice exercise learn basic matlab i'll leave you. luck!


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -