I can’t figure out why this bit of code isn’t working:
I have a vector j like this
j=[1;2;4;13;14;19;20]
I am trying to do
for i=2:7
j1=find(j(i)==(j(i-1)+1)
end
This should give me a j1 of [2,5,7] right? For some reason it’s giving me a j1 of either [1] or [0]
Any help would be greatly appreciated, also I am not tied to using find. I just need the indices of j where there is a discontinuity, i.e. for the j I posted it should tell me where it jumps from 1,2 to 4 and from 4 to 13,14 etc.
You can accomplish what you want in a much easier way:
Regarding your code:
findcan be vectorized, no need to useforloopj1. Instead, you can doj1(end+1) = ..