我正在尝试获取一个排序函数,它接受如下所示的数组:
0 2
1 5
2 3
3 0
4 1
5 4并按循环对其进行排序,即它应该输出
0 2
2 3
3 0
1 5
5 4
4 1有什么内置的东西吗?或者如何以一种精益的方式完成这件事?
发布于 2020-09-28 22:33:57
这很管用。
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
endhttps://stackoverflow.com/questions/64101755
复制相似问题