当前位置:网站首页>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.
边栏推荐
猜你喜欢
随机推荐
解决跨域的方法 --- Proxy
数据库性能优化的误区!
golang时间-时间戳的获取-转换-计算
makefile——library
【个人向】线性表复习
网络运维系列:二级域名启用与配置
LAMP环境 源码编译安装(Apache 2.4.52 +mysql 8.0.28+php 8.1.3)
搭建Spark开发环境
CUDA programming based on Visual Studio 2015 (1): basic configuration
How to tick the word box?
Mysql开启日志并按天进行分割
GC垃圾收集器G1
WEB自动化之多窗口操作、切换frame、弹窗处理
【时间序列模型】AR模型(原理剖析+MATLAB代码)
ADB常用命令--测试人员必备
RTMP, RTSP, SRT 推流和拉流那些事
Linux下mysql的彻底卸载
Mysql索引优化二
Dcoker的安装及使用命令
Homebrew的简单介绍