Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
 
 
主题工具 显示模式
旧 2019-12-10, 20:30   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 MATLAB pdist函数

我正在使用pdist命令来查找存储在矩阵中的x和y坐标之间的距离。

X = [100 100; 0 100; 100 0; 500 400; 300 600;]; D = pdist(X,'euclidean') 返回15个元素的向量。 :

[0.734979755525412 3.40039811339820 2.93175207511321 1.83879677592575 2.40127440268306 2.75251513299386 2.21488402640753 1.10610649500317 1.81674017301699 0.903207751535635 1.99116952754924 1.05069952386082 1.24122819418333 1.08583377275532 1.38729428638035] 有没有一种方法可以将这些距离与它们所源自的坐标相关联,即将它们存储在具有常规行形式的矩阵中:

[Length xcoordinate1 ycoordinate1 xcoordinate2 ycoordinate2] 找到的每种长度都有一行?

提前致谢



回答:

%# define X, D X = [100 100; 0 100; 100 0; 500 400; 300 600;]; D = pdist(X,'euclidean'); %# find the indices corresponding to each distance tmp = ones(size(X,1)); tmp = tril(tmp,-1); %# creates a matrix that has 1's below the diagonal %# get the indices of the 1's [rowIdx,colIdx ] = find(tmp); %# create the output out = [D',X(rowIdx,:),X(colIdx,:)];

更多&回答...
poster 当前离线   回复时引用此帖
 


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 05:01


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.