Your code is not written as a function. You do not initialize all arrays to definite size before you use them. When you run your code multiple times, sometimes the new arrays are going to be smaller than on the previous run, but because you did not initialize them, they are going to keep the size of the previous run. That can lead to indexing errors when you then use the entire array instead of just the part known to be valid.
Note:
Your code surrounding "match" could be much more efficient. It could just be
with no loops, and using it could be
matchedPoints1 = matchedPoints1(match);
matchedPoints2 = matchedPoints2(match);
In your current expression match(:)&match(:)>0, the first part is true for all non-zero entries in match, so it is only false for entries which are 0. The second part is only true for entries that are positive. But entries that are 0 are never positive, so the second part would also be false for 0, so the & part is redundant. Therefor match(:)>0 would be enough. But your match array is only 0 and 1, and in the case of 0 and 1, match(:)>0 is the same as match(:)~=0 which in turn is the same as just writing match(:) . As well, the value being indexed into is not two dimensional and neither is match, so the (:) does not add value:
>> ABC = 1:10
ABC =
1 2 3 4 5 6 7 8 9 10
>> ABC([3:5].')
ans =
3 4 5
>> ABC([3:5])
ans =
3 4 5
so using a column vector as an index does not matter. So you can skip the (:) and just use match as the index.
Best Answer