Info

This question is closed. Reopen it to edit or answer.

I was building an algorithm and got stuck here, I am not able to go back to the while loop after the if statement evaluates to true. Could you please help me. My code is as follows

1 view (last 30 days)
a=input b=input
while(1)
c=statement;[m,n]=size(c);
x=0;
for i=1:m
for j=1:n
if(c(i,j)==1)
x=x+1;
end
end
end
s=a-c;
if (x>0)
a=altered_a
p=p+1;
else
end
break
end

Answers (2)

Image Analyst
Image Analyst on 8 Apr 2015
Just use the built-in function to get the skeleton:
skeletonImage = bwmorph(a, 'skel', inf);

Image Analyst
Image Analyst on 8 Apr 2015
OK . . . Completely different question now that you've edited it! For this new question, if your "if" inside your while evaluates to true and you want to continue with the while loop, then change these lines:
if (x>0)
a=altered_a
p=p+1;
else
end
break
to these lines:
if (x>0)
a=altered_a
p=p+1;
% Then continue with the while loop.
else
break; % Exit from while loop
end
  3 Comments
Image Analyst
Image Analyst on 8 Apr 2015
And why do you think it doesn't come out of the if after it hits the p=p+1 line???? Of course it does , and then it will execute the while on the next iteration just like you want. Do you think the program just abruptly halts at that point, or breaks out of the loop? It will only leave the loop if it goes into the "else" block.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!