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

2 ビュー (過去 30 日間)
Aru hazari
Aru hazari 2015 年 4 月 8 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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