Sunday, 15 February 2015

matlab - Finding lengths of 0's separating islands of 1's and assigning them -


I have a vector with the option of 0 and 1 and want to change the length of zero before each "1" This is it For example, I have X and want to go by y:

  x = [0 0 1 0 0 0 0 0 0 0 0 0 1 1 0 0 1] Y = [0 0 2 0 0 0 0 0 0 0 0 0 0 2 2]  

I appreciate any suggestions for how to achieve this.

with an attitude & amp; -

 % // Find the initial array, with zero and in the form of input y, xy = zero (size (x))% // places / index where the new value ID Will be kept = address (x)% // Calculate new values ​​which will be differentiated values ​​of index% 3 and decrease between 2 to% to zero for 1. We need to add index array with a zero% // initially for zero-zero values ​​in xy (idx) = diff ([0 idx]) - 1  
< / Html>

No comments:

Post a Comment