Info

此问题已关闭。 请重新打开它进行编辑或回答。

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 次查看(过去 30 天)
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

回答(2 个)

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

Image Analyst
Image Analyst 2015-4-8
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 个评论
Image Analyst
Image Analyst 2015-4-8
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!

Translated by