Error on nested loop?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have programmed as one big for loop contain two small loop. But the problem is first loop(%TOP CHECKING) only running. sencond loop(%Down checking) not running.
my code bellow
or=1; [r c d]=size(RGB);
for i=1:tblob x=shape(i).cen(1,:); y=shape(i).cen(2,:); xi=x; yi=y; w=0;flag=0; %TOP CHECKING
for(trail=1:1000) color_val=color(y,x); RGB(y,x,1)=240; RGB(y,x,2)=31; RGB(y,x,3)=191;
if((color_val==shape(i).color)&w==0) if(r>y) y=y+1; end %x=x-1; else if (color_val==White) w=1; if(r>y) y=y+1; end %x=x-1; else if(color_val==Black) flag=1; else %T juction if (color_val==[240,31,191])
order(or).order=[xi,yi,x,y];
or=or+1;
RGB=line(xi,yi,x,y,RGB);
flag=1;
else
for i=1:tblob
xa=shape(i).cen(1,:);
ya=shape(i).cen(2,:);
if (color_val==shape(i).color)
if(x-40<xa<x+40)
if(y-86<ya<y)
xj=xi;
yj=ya;
shape(i).cen(1,:)=xi;
order(or).order=[xi,yi,xj,yj];
or=or+1;
RGB=line(xi,yi,xj,yj,RGB);
flag=1;
end
end
end
end
end
end
end
end
if (flag==1)
break;
end
end
%DOWN CHECKING
for(trail=1:1000) color_val=color(y,x); RGB(y,x,1)=240; RGB(y,x,2)=31; RGB(y,x,3)=191;
if((color_val==shape(i).color)&w==0) if(r>y) y=y-1; end %x=x-1; else if (color_val==White) w=1; if(r>y) y=y-1; end %x=x-1; else if(color_val==Black) break; else %T juction if (color_val==[240,31,191])
order(or).order=[xi,yi,x,y];
or=or+1;
RGB=line(xi,yi,x,y,RGB);
flag=1;
else
for i=1:tblob
xa=shape(i).cen(1,:);
ya=shape(i).cen(2,:);
if (color_val==shape(i).color)
if(x-40<xa<x+40)
if(y-86<ya<y)
xj=xi;
yj=ya;
shape(i).cen(1,:)=xi;
order(or).order=[xi,yi,xj,yj];
or=or+1;
RGB=line(xi,yi,xj,yj,RGB);
flag=1;
end
end
end
end
end
end
end
end
if (flag==1)
break;
end
end
end
imshow(RGB)
0 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Data Type Conversion dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!