2D Matlab中数据之间的距离矩阵 [英] Matrix of distances between data in 2d Matlab

查看:313
本文介绍了2D Matlab中数据之间的距离矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有四个1-by-n矩阵.前两个矩阵表示n点在2D平面中的位置(位置的x和y分量).后两个矩阵表示2D平面中另一个n点的位置.

I have four 1-by-n matrices. The first two matrices represent the position of n points in the 2D plane (x and y component of position). The second two matrices represent the position of another n points in the 2D plane.

我想创建一个n-by-n矩阵(例如M),对于M(i,j)是第一个矩阵中的点i与第二个矩阵中的点j之间的距离.

I want to create an n-by-n matrix (say M) for which M(i,j) is the distance between point i in the first matrix and point j in the second matrix.

有人可以帮忙吗?任何答案都将受到高度赞赏.

Could anyone help? any answers are highly appreciated.

  • n很大,所以我正在寻找一种有效的方法

推荐答案

您可以使用pdist2进行此操作(请参见文档):

You can do that using pdist2 (see documentation):

x1=[1,2,3,4,5];
y1=[6,7,8,9,10];
x2=[1,1,1,1,2];
y2=[8,3,1,2,3];
mat1=[x1',y1'];
mat2=[x2',y2'];
M = pdist2(mat1,mat2)

这篇关于2D Matlab中数据之间的距离矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆