Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

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 vue (au cours des 30 derniers jours)
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

Réponses (2)

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

Image Analyst
Image Analyst le 8 Avr 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 commentaires
Image Analyst
Image Analyst le 8 Avr 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.

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by