Error on nested loop?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!