1

I have this function below, but the if statement inside the for loop doesn't work. I tried <= instead of < and also round(), but they didn't work.

function points1=tracker(count1,points1,u,v,I2)

for j=1:count1

   if  (points1(1,j) < size(u,1))&&(points1(2,j) < size(u,2))

       points1(1,j)= points1(1,j)+v(points1(1,j),points1(2,j));
       points1(2,j)= points1(2,j)+u(points1(1,j),points1(2,j));
       I2(round(points1(1,j)),round(points1(2,j)))=255;

   else

       points1(:,j)=[];
       count1=count1-1;
       j=j-1;

   end

end

    figure, imshow(I2)

end
2
  • 3
    What exactly doesn't work about it? Commented Jul 29, 2013 at 15:08
  • Did my answer solve your question? Commented Aug 2, 2013 at 20:53

1 Answer 1

8

You're trying to change the increment of the for loop, j, from within the loop (your j=j-1 line). You can't do this. The documentation for for states:

Avoid assigning a value to the index variable within the body of a loop. The for statement overrides any changes made to the index within the loop.

You'll need to use a while loop instead or find another way of doing what you need using an intermediate variable.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.