1
현재 matlab에서 맵 처리를하고 있습니다. 이제 미로를 해결하고 미로의 길을 잡았습니다. 이제 나는지도에서 전환점을 얻었습니다. 그러나이 주소 픽셀은 올바른 순서가 아닙니다. 그래서 올바른 순서로 픽셀 주소의 잘못된 순서를 주문하고 싶습니다.특정 조건에서 픽셀 주소를 정렬하는 방법은 무엇입니까?
잘못된 순서 :
shape(1).cen=[28;136];
shape(2).cen=[122;136];
shape(3).cen=[344;391];
shape(4).cen=[548;493];
shape(5).cen=[548;191];
shape(6).cen=[344;191];
shape(7).cen=[122;391];
올바른 ORDR :
map(1).cen=[28;136];
map(2).cen=[122;136];
map(3).cen=[122;391];
map(4).cen=[344;391];
map(5).cen=[344;191];
map(6).cen=[548;191];
map(7).cen=[548;493];
내 코드는 다음과 같습니다 : -
`map(1).cen=[28;136];
o=0; order=1;xflag=0;yflag=0;
k=length(shape); %indicates the total elements in shape.cen structure
for (j=1:k)
order=order+1; o=o+1;
if (j==1)
x=map(1).cen(1,1);
y=map(1).cen(2,1);
for(i=1:k)
xi=shape(i).cen(1,1);
yi=shape(i).cen(2,1);
if((x==xi)||(y==yi))
if(x==xi)
map(order).cen(1,1)=xi;
map(order).cen(2,1)=yi;
xflag=1;
break;
else
(y==yi)
map(order).cen(1,1)=xi;
map(order).cen(2,1)=yi;
yflag=1;
break;
end
end
end
end
x=map(o).cen(1,1);
y=map(o).cen(2,1);
for(i=1:k)
xi=shape(i).cen(1,1);
yi=shape(i).cen(2,1);
if(xflag==1)
if(y==yi)
map(order).cen(1,1)=xi;
map(order).cen(2,1)=yi;
xflag=0;
yflag=1;
break;
end
end
if (yflag==1)
if(x==xi)
map(order).cen(1,1)=xi;
map(order).cen(2,1)=yi;
xflag=1;
yflag=0;
break;
end
end
end
end
이
`
당신에 대해 말하는 경우 '주문'보다 어떻게 든 정렬해야합니다. 당신은 무엇을 정렬합니까? 이 예제에서 첫 번째 좌표의 값을 기준으로 정렬 순서를 변경하는 것 같습니다. – Marcin
체크 아웃 [sortrows] (http://www.mathworks.com/help/matlab/ref/sortrows.html) –