当前位置:网站首页>The difference and connection between dist, pdist and pdist2 in MATLAB
The difference and connection between dist, pdist and pdist2 in MATLAB
2022-08-02 16:36:00 【智赵】
一、dist
distis the Euclidean distance weighting function.
Z = dist(W,P);
W:指定S行RColumn weight matrix.
P:指定表示R行Q列的输入矩阵,Qis the input column vector.
函数的返回值Z为一个S行Q列的矩阵.
例1:
>> W = rand(4,3)
W =
0.8342 0.6690 0.1222
0.0156 0.5002 0.6712
0.8637 0.2180 0.5996
0.0781 0.5716 0.0560
>> P = rand(3,1)
P =
0.0563
0.1525
0.0196
>> Z = dist(W,P)
Z =
0.9394
0.7396
0.9962
0.4212
二、pdist
D = pdist(X);
用法:对于一个M×N的矩阵X,pdistCalculate the mutual distance of each pair of row vectors,By default, the Euclidean distance formula is used;The return value of the function is a vectorD,Dis has a row,(m*(m-1)/2)列的行向量.
例2-1:
>> X = randn(4,2)
X =
0.0378 1.5239
-0.3636 0.5458
0.1496 2.0099
-1.9445 1.4167
>> D = pdist(X)
D =
1.0572 0.4987 1.9852 1.5514 1.8049 2.1765
D = pdist(X,distance); Specifies the distance formula to use.
distanceThe following parameters can be selected:
'euclidean' - 欧氏距离(默认)
'squaredeuclidean' - 平方欧氏距离
'seuclidean' - 标准化欧氏距离
'cityblock' - 城市街区距离
'minkowski' - 闵可夫斯基距离.默认指数为2,To specify another index,请使用D = PDIST(X,'minkowski',P); 其中,指数Pis a scalar positive value.
'chebychev' - 切比雪夫距离(Maximum coordinate difference)
'mahalanobis' - 马氏距离
'cosine' - 夹角余弦距离
'correlation' - 相关距离
'spearman' - Spearman distance
'hamming' - 汉明距离
'jaccard' - 杰卡德距离
function - 用 @ Specify a function as the formula for distance calculation,例如@DISTFUN
例2-2:
>> X = rand(3,2)
X =
0.8147 0.9134
0.9058 0.6324
0.1270 0.0975
>> D = pdist(X,'minkowski')
D =
0.2954 1.0670 0.9448
三、pdist2
D = pdist2(X,Y);
用法:设X为一个M行N列的矩阵,Y为一个P行Q列的矩阵,the return value of the functionD为一个M行P列的矩阵.
pdist2计算XAny row vector AND of YThe distance of any row vector in ,By default, the Euclidean distance formula is used.
例3-1:
>> X = randn(2,3)
X =
-0.4336 3.5784 -1.3499
0.3426 2.7694 3.0349
>> Y = randn(2,3)
Y =
0.7254 0.7147 -0.1241
-0.0631 -0.2050 1.4897
>> D = pdist2(X,Y)
D =
3.3236 4.7449
3.7879 3.3763
D = pdist2(X,Y,distance); Specifies the distance formula to use.
pdist与pdist2中distanceThe selected parameters are the same.
The above is in usedist与pdist、pdist2difference between these three functions.
dist与pdist、pdist2The connection between can passMATLAB自带的pdist、pdist2The entry parameters of the function can be seen:
[D,I] = pdist2(X,Y,dist,varargin)
Y = pdist(X,dist,varargin)
pdist、pdist2These two functions are also called during the implementationdist函数,Used to calculate the distance between two vectors.
边栏推荐
猜你喜欢
随机推荐
为什么 RTP 的视频的采样率是 90kHz ?
解决跨域问题的方法 --- JSONP
Template series-union set
test2
ADB常用命令--测试人员必备
DOM —— 事件代理
支付系列文章:PCI合规能力建设
时频分析之Wigner-Ville分布
nvm管理node版本 nodenpm不是内部或外部命令,也不是可运行的程序
appium 报错:AttributeError:
一线大厂研发流程(转载自鱼皮)
华为单臂路由配置,实现不同vlan之间的通信
【故障诊断】基于PSO_VMD_MCKD方法的风机轴承微弱故障诊断
RouteOS 导入至PVE
GC垃圾回收ZGC
解决跨域的方法 --- Proxy
小知识系列:Fork之后如何与原仓库分支同步
异常抛出错误
小知识点系列:StringUtil.isEmpty()与StringUtil.isBlank()的区别
网络运维系列:Ubnt ER-X初始化和开启硬件NAT









