sorting - 对两个向量数组进行排序以获得循环
问题描述
我正在尝试获取一个排序函数,该函数采用如下数组:
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
推荐阅读
- javascript - JavaScript 中的大于运算符问题
- .net - EF核心加入包括
- python - Python:如何将 QTableWidget 的列设置为以日期格式显示
- powerbi - 如何显示未过滤的数据
- google-cloud-platform - 已超出 Terraform 转发规则配额
- vue.js - 如何从 graphql 查询中访问参数
- json - 雪花表中 json 数据的解析字段将多行插入新的雪花表
- amazon-web-services - 允许使用 CDK 公开访问 AWS Aurora VPC 集群
- types - 在python数据框中将对象转换为字符串
- amazon-web-services - 如何设置从现有 API 获取数据的 AWS Kinesis Data Stream?