PDA

View Full Version : matlab help...distance/length


freezingbum
12 May 2007, 07:19pm
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..

shwaip
12 May 2007, 09:23pm
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.