我正在尝试获得一个排序函数,该函数接受如下数组:
0 2
1 5
2 3
3 0
4 1
5 4
并按周期对其进行排序,即应输出
0 2
2 3
3 0
1 5
5 4
4 1
有什么内置的东西吗?或者如何以精益的方式完成这项工作?
这对有效
y=[]; %% results go here
k=1;
while length(x)>0 %% items left? loop
_x=x(k,:); %% local copy
y=[y ; _x]; %% append
x(k,:)=[]; %% remove from array
try
k=find(x(:,1)==_x(2)); %% find next
catch
k=1; %% no next? complete cycle, start over
end
end