matlab help...distance/length

edited May 2007 in Science & Tech
How do I find the distance between the two ones in this case?

M =

0
0
0
0
1
0
0
0
-1
0
0
0
1
0
0
0
-1
0
0
0


in this case the distance would be 8 but the number of zeros between will change...there will always be two 1's and two -1's..

Comments

  • shwaipshwaip bluffin' with my muffin Icrontian
    edited May 2007
    diff(find(a==1))

    edit:

    You should be able to write a for loop that calculates the difference, unless you really have no idea how to use matlab.
Sign In or Register to comment.