matlab pdist2. Nov 8, 2013 at 9:26. matlab pdist2

 
 Nov 8, 2013 at 9:26matlab pdist2  This norm is also

linprog 参数选择:linprog(c, A_ub, b_ub, A_ed, b_ed, bounds=None) 参数解释—>>> c:价值向量,只规划最小值,若规划最大值需改为-c,但注意得出的结果应再加负号即为所求最大值; A_ub和b_ub:分别对应于不等式约束的向量,注意只取小于等于时的数组,而且A_ub. In human motion analysis, a commond need is the computation of the distance between defferent point sets. I want a supervised learning on a distance metric. computes the distance between objects in the data matrix, , using the method specified by can be any of the following character strings that identify ways to compute the distance. The distance between each sample in A and each sample in B can be calculated as follows: First, define a matrix D of size 75x50, s. It shows a path (C:\Program Files\MATLAB. . clc; % Clear the command window. GPU Arrays. pdist_oneLine. I know the distance(lat1,lon1,lat2,lon2) command is the suitable for this but I want to use pdist2 command. See the Wikipedia website. Each row of both matrices identifies a point in 2D space. pdist2 Pairwise distance between two sets of observations. Tags matlab; array; Products MATLAB; Community Treasure Hunt. I'd like to compute the average distance between each observation in my matrix, but pdist() fails here, because apparently it would take. Sign in to answer this question. Add the %#codegen compiler directive (or pragma) to the entry. PixelList, CCstats (2). matlab pdist2,matlab中pdist2函数; windows 10 bash change PS1; linxu中删除指定时间之前的文件shell脚本; react中如何做成 tab 切换的效果; __declspec的英文含义; 从零复现PyTorch版(3) webpack报错:Invalid options object. Computes the distance between m points using Euclidean distance (2-norm) as the distance metric between the. . Q&A for work. One way is to call regionprops() to get the centroids of the two blobs. The problem seems to be that. 2. The problem seems to be that xtrack, ytrack are row vectors, not column vectors. Matlab pdist2 : Out of memory Ask Question Asked 6 years, 7 months ago Modified 6 years, 7 months ago Viewed 267 times 1 I have a vector X which contain x. 0670 0. harmmean: Compute the harmonic mean. function Distance = euclidean (x,y) % This function replaces the function pdist2 available only at the Machine. distance. Introduction to GPU Computing with MATLAB. Copy. optimize. D can be the output of pdist or pdist2, or a more general dissimilarity vector or matrix conforming to the output format of pdist or pdist2, respectively. But for a small number of huge arrays loops and isequal is faster. Calculating Euclidean distance of pairs of 3D points in matlab Is it possible to write a code in matlab withoutmatlab pdist2,matlab中pdist2函数; windows 10 bash change PS1; linxu中删除指定时间之前的文件shell脚本; react中如何做成 tab 切换的效果; __declspec的英文含义; 从零复现PyTorch版(3) webpack报错:Invalid options object. Then pdist returns a [3 x 3] D matrix in which the (i, j) entry represents the distance between the i-th observation in X and the j-th observation. To save memory on the device, you can separate training and prediction by using kmeans and pdist2, respectively. distance used is L1 norm. . computes the Euclidean distance between pairs of objects in . I am trying to compute the gradient of a Gaussian Process when the training data set is given by N X D in MATLAB. Learn more about pdist2, matlab, function, warning When I calculate cosine with pdist2, it often warn me that some points have small relative magnitudes, making them effectively zero. Answers (2) You can do this with the pdist2 function. Learn more about custom distance function, pdist, pdist2, @distfun, divergence, kl divergenceI have a trajectory like this: We assume that each red star marker can broadcast its coordinate to the green circle markers which are located within a radius of 5 units from its own position. pairwise distance between rows of matrix A and B. For code generation, define an. tic d = sqrt (sum ( (p1-pn). For example, you can find the distance between observations 2 and 3. Which is "Has no license available". Using pdist with two matrix's. MY-by-N data matrix Y. View self-paced courses | Search documentation, examples, and videos. Now, it is confirmed that I do not have a license. Generate Code. In this workflow, you must pass training data, which can be of considerable size. % ZI is a 1-by-n vector containing a single observation. John D'Errico on 26 May 2019. If you want to order the points from B by their distance to the r th point in A then you can sort the r th row of the pairwise distance matrix. distances = pdist2 (xySet1, xySet2);Dear MATLAB-Community, I would like to calculate the distances between each entry in M (1 113 486 x 2) and N (1 960 000 x 2) and store the indices for the distances that are within a tolerance val. AnyLogic. ##Android日期类##Unix时间戳在计算上最为方便和灵活,效率也高;而Date和Calendar则在一些具体的日期计算上更为便利。유클리드 거리를 계산합니다. In Matlab there exists the pdist2 command. k2 = dsn (single (x),single (xi)); but this is still not enough for me. Typically I use pdist2 like this D2 = pdist2(x,y). it could be little slower than pdist2. . If observation i in X or observation j in Y contains NaN values, the function pdist2 returns NaN for the pairwise distance between i and. 19. As a side note, you may want to check Histogram intersection distance, if your feature is a histogram. Try something like E = pdist2 (X,Y-mean (X),'mahalanobis',S); to see if that gives you the same results as mahal. squareform returns a symmetric matrix where Z (i,j) corresponds to the pairwise distance between observations i and j. 2. One-line implementation of both MATLAB's pdist and pdist2 functions. Google it if you want the details. Use the distance matrix to create a logical adjacency matrix that shows two point are neighbors if distance between them is less. For code generation, define an. Тепер я хочу створити a mxn матриця така, що (i,j) елемент представляє відстань від iго точка mx2 матриця до jго точка nx2 матриці. Utilice kmeans para crear grupos en MATLAB® y utilice pdist2 en el código generado para asignar nuevos datos a grupos existentes. What i want to do is to write a code, that does not involve loops and pdist2,. Matlab taking too much time in computing mex function for large array. Copy. between each pair of observations in the MX-by-N data matrix X and. d(u, v) = max i | ui − vi |. calculate euclidean distance using matlab for 3 vectors pdist2 MathWorks Makers of MATLAB and Simulink May 1st, 2018 - This MATLAB function returns the distance between each pair of observations in X and Y using the Euclidean distance For code generation pdist2 uses Euclidean distance ED calculation in matlab MATLABMATLAB GPU Computing Support for NVIDIA CUDA Enabled GPUs WebGenerate CUDA code directly from MATLAB for deployment to data centers, clouds, and embedded devices using GPU Coder™. cosined=sqrt (sum (abs ( (a-b). Any help. To save memory on the device, you can separate training and prediction by using kmeans and pdist2, respectively. . Use kmeans to create clusters in MATLAB® and use pdist2 in the generated code to assign new data to existing clusters. Js Goh on 18 Sep 2015. Y would be the query points. m","path":"MyData. y = squareform (Z)The present code is a set of three Matlab functions that provide calculation of six metrics: - Euclidean distance, which vary in the range of [0 : Inf]. calculate_distance. Z = squareform (D) Z = 3×3 0 0. % ZI is a 1-by-n vector containing a single observation. x = 177136 x 1 y = 177136 x 1 I have the following query points to which I. Pass Z to the squareform function to reproduce the output of the pdist function. Nov 8, 2013 at 9:26. Mahalanobis distance in matlab: pdist2() vs. Warning: Converting input data to single. I am getting the following error: Theme. 0. Generate Code. Then pdist2 should work. which -all pdist will list all the pdist MATLAB files in your MATLAB path. Then Matlab's unique() solves the problem efficiently. However this distance need extra argument which seems possible using combination of anonymous function. You need to take the square root to get the distance. If K is greater than MX, PDIST2 returns an MX-by-MY distance matrix. Your third party file c: oolboxclassifypdist2. 'cosine') varies between 0 and 2. . Learn more about TeamsAnswers (2) You can do this with the pdist2 function. Sorted by: 1. Use kmeans to create clusters in MATLAB® and use pdist2 in the generated code to assign new data to existing clusters. Learn more about unrecognized fuction or variable xThis MATLAB function returns the distance between each pair of observations in X and Y using the metric specified by Distance. plot (xi,t1,'r',xi,t2,'b'); legend ( {'Manual','Pdist2'}) Which probably suggests that any differences in time between pdist2 and manual calculation are negligible and more dependent on the current background state of the CPU. pdist2 extracted from open source projects. 0000 %# Note that I get different results than your example!Very clever - I wouldn't have thought about the pdist2 function (+1). Nov 8, 2013 at 9:26. I need to develop a function to create an array of points and find the distances between every pair of points. Accepted Answer. To save memory on the device, you can separate training and prediction by using kmeans and pdist2, respectively. 判别分析时,通常涉及到计算两个样本之间的距离,多元统计学理论中有多种距离计算公式。MATLAB中已有对应函数,可方便直接调用计算。距离函数有:pdist, pdist2, mahal, squareform, mdscale, cmdscale. This function can do both - it will function like pdist if only one set of observations is provided and will function like pdist2 if two. For example, you can find the distance between observations 2 and 3. I calculated out the distance from every point in X to every point in Y using the pdist2 tool. But, the function is easy to write and can be passed in as a handle to pdist2. 普通に[MATLAB マハラノビス距離]でググるとmahalという関数がヒットしますが、この関数では、事前計算した共分散行列を受け付けてくれません。. – Nicky Mattsson. Note that v here in many MATLAB functions can be set by itself, do not necessarily have to take the standard deviation, can be based on the importance of each variable to set different values, such as the Knnsearch function in the Scale property. My problem is taking those distances out of the matrix and finding the smallest combined distance for each unique set of X to Y measurements. Let X be an MxP matrix representing m points in P-dimensional space and Y be an NxP matrix representing another set of points in the same space. This code was developed primarily as a learning tool for Topological Data Analysis. It is much faster than computing the distances using a nested for loop. This function computes the M-by-N distance matrix D where D(i,j) is the distance between. Copy. In this workflow, you must pass training data, which can be of considerable size. If a is m x r and b is n x r then. train_labels is an N x 1 cell array, where each entry is a. – am304. 2. 9448. mahal returns the squared Mahalanobis distance. Generate C code that assigns new data to the existing clusters. pdist is working fine and the stats toolbox is set in the path. ^2,2)); % calculate the distance between these toc Does anyone else have a clever idea that would optimise this - even just by a tiny. >> jaccard_similarity = 1 - pdist2(bin_counts_a,bin_counts_b,'jaccard') jaccard_similarity = 0 gives 0 because each entry in bin_counts_b is (slightly) different from that in bin_counts_a . For example, this is a required step in the ICP point set registration algorithm. % ZJ is an m2-by-n matrix containing multiple observations. pdist and pdist2 can calculate the city block distance. Y = pdist(X, 'euclidean'). X is a 50*3 matrix, Y is a 60*3 matrix. But recently I saw pdist2 and I think it can help me avoid the loop. Rx is then recalculated into the number of sampled samples to each pixel, i. Thanks for your help. Learn more about pdist2 Statistics and Machine Learning ToolboxMar 8, 2021 at 17:55. If you look in the matlab documentation for mahal function it says: X and Y must have the same number of columns, but can have different numbers of rows. For a dataset made up of. Density-Based Spatial Clustering of Applications with Noise (DBSCAN) identifies arbitrarily shaped clusters and noise (outliers) in data. % ZJ is an m2-by-n matrix containing multiple observations. I want to compute the distance between two vectors by using Jaccard distance measure in matlab program. MY-by-N data matrix Y. cityblockSimilarity. The appended image_domain function models the specimen as homogeneous. Generate Code. Hi, So if I have one 102x2 matrix of x,y coordinates, and another 102x2 matrix of x,y coordinates, can pdist be used to compare all the rows in matrix 1 with the rows in matrix 2?. pdist and pdist2 can calculate the city block distance. % Autor: Ana C. 相同的结果,我想有两种不同的方法来计算两组数据之间的马氏距离,就像你上面解释的那样: 1) 将样本集中的每个数据点与参考分布计算出的mu和sigma矩阵进行. Could I modify in some manner pdist2 command?comparing histograms with matlab through pdist2. if you don't have a working pdist2, use the following code. Hot Network Questions Probability threshold in ROC curve analyses Can one walk across the border between Singapore and Malaysia via the Johor–Singapore Causeway at any time in the day/night? Using `any` to indicate a wildcard value. Define an entry-point function named findNearestCentroid that accepts centroid positions and new data, and then find the nearest cluster by using pdist2. The biggest distance using pdist2() will be from one end of the line to the opposite end of the other line. This means that I want to create a custom distance to feed it to the classifier. Mahalanobis distance between two vectors in MATLAB. For more information, see Run MATLAB Functions in Thread-Based Environment. – Suever. pdist2 computes the distances between observations in two matrices and also returns a distance matrix. Given the matrix mx2 and the matrix nx2, each row of matrices represents a 2d point. and pdist2() where I plotted all 3 of the closest pairs. Therefore, pydist2 is a python package, 1:1 code adoption of pdist and pdist2 Matlab functions, for computing distance between observations. You can use the pdist2 MATLAB / Octave function to calculate pairwise distances between two sets of observations. ^2; where x and y are nx3 matrices for large n. Copy. D = pdist2 (X,Y) returns a matrix D containing the Euclidean distances. . figure. Mahalanobis distance has no meaning between two multiple-element vectors. function D = pdist2( X, Y, metric ) ↑ Error:. Copy. Dear Gentlemen i face problem when i use pdist2 function of hamming distance between two binary images in same size, the output result is an array not a percentage value, where i want to use hamming distance to calculate the percentage difference between two binary images:Using pdist with two matrix's. [D,I] =. . 使用Matlab计算各种距离. It shows a path (C:Program FilesMATLAB. For example instead of @dist(ZI,ZJ) I should send something like @dist(ZI,ZJ,PD) which PD is a parameter (a matrix). Engineers can use GPU resources without having to write any. Idx = knnsearch (X,Y) finds the nearest neighbor in X for each query point in Y and returns the indices of the nearest neighbors in Idx, a column vector. I cannot found any tips on how to convert this statement: matlab. Rows of X and Y correspond to observations, That is, it works on the ROWS of the matrices. Learn more about sorting points, matrix manipulation, comparing distances, pdist2, indexing . Copy. まぁそれでもDNNがボトルネックなので大した影響はないのですが。代わりにpdist2という関数があり. Hooray!!! You have just reached the end of this article. So, you showed the formula for the square of the distance. . Improve this answer. out = 1×10. I was wondering if there is a built in matlab. end. Just wanted to let you know that pdist2 in MATLAB uses 'Euclidean' distance by default. %. The less details have to be guessed, the more likely does the answer match your needs. Using a rule based on the majority vote of the 10 nearest neighbors, you can classify this new point as a versicolor. Use pdist2 to compute distance matrix of x and y. This means that I want to create a custom distance to feed it to the classifier. D = pdist ( [Y (:) Z (:)] ); % a compact form D = squareform ( D ); % square m*n x m*n distances. 欧氏距离: 也可以用表示成向量运算的形式: (4)Matlab计算欧氏距离 Matlab计算距离主要使用pdist函数。若X是一个M×N的矩阵,则pdist(X)将X矩阵M行的每一. Minkowski's distance equation can be found here. 2954 1. pdist2 (P1,P2, 'cityblock'); But in my case, I want to use the columns of my matrices col as follows. * t at first and throws it from the cache to the slow RAM. {"payload":{"allShortcutsEnabled":false,"fileTree":{"classify":{"items":[{"name":"private","path":"classify/private","contentType":"directory"},{"name":"Contents. . Learn more about mahalanobis, mahal, pdist2, pairwise, difference, versus . You can get these out in a 16 by 16 2-D array using pdist2 (). linux 网络的配. [xNorth,yEast,zDown] = geodetic2ned (lat,lon,h,lat0,lon0,h0,spheroid) transforms the geodetic coordinates specified by lat , lon, and h to the local north-east-down (NED) Cartesian coordinates specified by xNorth, yEast, and zDown. you can also compute the distance between every element and every element of the other array using the function pdist2(). In Matlab, the D = pdist(X, Y) function computes pairwise distances between the two sets of observations X and Y. PostCSS Loader. The function you pass to pdist must take . matlab R2012a - 8. % ZI is a 1-by-n vector containing a single observation. . >> jaccard_similarity = 1 - pdist2(bin_counts_a,bin_counts_b,'jaccard') jaccard_similarity = 0 gives 0 because each entry in bin_counts_b is (slightly) different from that in bin_counts_a . PostCSS Loader. I simply call the command pdist2(M,N). Learn more about pdist2, error, stats MATLAB Every time I want to use pdist2, I get the following error: Undefined function 'pdist2mex' for input arguments of type 'double'. For assessing the similarity between the histograms, 'cosine' is probably a more meaningful option than 'jaccard' . I want the haversine distance to be more specific. Hello all, I am very new to Matlab and I am having quite a bit of difficulty understanding how to calculate the distance between pairs of points in a 2-D space. between each pair of observations in the MX-by-N data matrix X and. For code generation, define an. 2种计算方式,一种直接利用pdist计算,另一种. MATLAB (matrix laboratory) is a numerical computing environment and fourth-generation programming language. cdist(input,'minkowski', p=p) 等价。 Tensorflow 则支持 Tensor,但没有此API,需要手动实现,使用较为繁琐。Learn more about matlab, pdist2, templateknn, fitcecoc, kfoldloss, crossval MATLAB I want a supervised learning on a distance metric. But here's one possible cause: When you call pdist2 with a custom distance function, it should meet the following condition: A distance function must be of the form . i am currently doing project on image processing in matlab,. 5823 71. 输入 输入数据有多组。每组数据的第一行为以正整数n(0<n<100000),表示有n个馅饼掉在这条小径上。在结下来的n行中,每行有两个整数x,T(0<T<100000),表示在第T秒有一个馅饼掉在x点上。Description. I need to build a for loop to calculate the pdist2 between the first row of A and all the rows of B, the second row of A and all. 判别分析时,通常涉及到计算两个样本之间的距离,多元统计学理论中有多种距离计算公式。MATLAB中已有对应函数,可方便直接调用计算。距离函数有:pdist, pdist2, mahal, squareform, mdscale, cmdscale. [D,I] = pdist2(X, X, 'squaredeuclidean', 'Smallest', k+1); D = D &lt; threshold; W. Idx = knnsearch (X,Y,Name,Value) returns Idx with additional options specified using one or more name-value pair arguments. From help pdist2: 'cosine' - One minus the cosine of the included angle between observations (treated as vectors) Since the cosine varies between -1 and 1, the result of pdist2 (. Note that generating C/C++ code requires MATLAB® Coder™. ^2))) Now I want to change euclidean into chi-square distance, does anyone know how to calculate chi-square distance between two vectors? 2 Comments. y = squareform (Z) comparison of two histograms using pdist2. This can be modified as necessary, if one wants to apply distances other than the euclidean. E=pdist2(X,Y-mean(X),'mahalanobis',S). This MATLAB function returns the distance between each pair of observations in X and Y using the metric specified by Distance. distfun must accept a matrix XJ with an arbitrary number of rows. 9448. The pairwise distances are arranged in the order (2,1), (3,1), (3,2). Copy. d(u, v) = max i | ui − vi |. The idx that results will have as many rows as first_xyz has, and the value will be the index of which second_xyz row is closest to that point; the mindist value will tell you how close it is. Idx has the same number of rows as Y. So, do you know how to make the calcul inside the. 9448. between each pair of observations in the MX-by-N data matrix X and. However, pdist2 is an optimized method to calculate the euclidean distances between points in two vectors. 9448. if you don't have a working pdist2, use the following code. % Learning toolbox. This can be done in pdist2. Here’s how to calculate the L2 Euclidean distance between points in MATLAB. Thus you need to take the transpose, telling MATLAB that its a 2000-D feature of a single example rather than 1-D feature for 2000 examples. Add a comment. Now, it is confirmed that I do not have a license. ^2));. distance = pdist2(trainpg. One immediate difference between the two is that mahal subtracts the sample mean of X from each point in Y before computing distances. squareform returns a symmetric matrix where Z (i,j) corresponds to the pairwise distance between observations i and j. Along the diagonal are the matching row cases. Usage notes and limitations: If you supply the argument that represents the order of the diagonal matrix, then it must be a real and scalar integer value. In the previous script pdist2 function tries to create matrix. 1. matlab pdist2,matlab中pdist2函数; windows 10 bash change PS1; linxu中删除指定时间之前的文件shell脚本; react中如何做成 tab 切换的效果; __declspec的英文含义; 从零复现PyTorch版(3) webpack报错:Invalid options object. See the Wikipedia website. Maybe the differences are due to the incorrect use of the indexes i and j. and pdist2() where I plotted all 3 of the closest pairs. (User points out that there can be problems if you accidentally have your own kmeans. Mahalanobis distance has no meaning between two multiple-element vectors. 2954 0 0. Hello, I am using matlab 2019a and I am trying to sort points based on comparing the distance between them. Learn more about pdist2 Statistics and Machine Learning Toolbox Mar 8, 2021 at 17:55. It seems that the pdist2 version lacks in efficiency due mainly to the element-wise squares, while Matlab now provides the 'squaredeuclidean' option to get this directly. I need to build a for loop to calculate the pdist2 between the first row of A and all the rows of B, the second row of A and all. Generate C code that assigns new data to the existing clusters. I use the pdist2 function to calculate the the distance between the points stored in matr. Given a matrix A of size [N,3] and a matrix B of size [M,3], you can use the pdist2 function to get a matrix of size [M,N] containing all the pairwise distances. Thus if you input a matrix with N points and one with M points, you get N*M distances. Location,labels) colormap (hsv (numClusters)) title ( 'Point Cloud Clusters')The loop is faster, because Matlab have to access the three used arrays X, Y and d6 locally only. squareform returns a symmetric matrix where Z (i,j) corresponds to the pairwise distance between observations i and j. I'm creating a volume from a very large number of points, created by accumulating a large number of point cloud objects in a box without overlapping any existing points. Note that generating C/C++ code requires MATLAB® Coder™. Add the %#codegen compiler directive (or pragma) to the entry. Pairwise distances between observations, specified as a numeric row vector that is the output of pdist, numeric square matrix that is the output of pdist2, logical row vector, or logical square matrix. 🄳. MY-by-N data matrix Y. For latitude and longitude, usually the haversine method is used. I am looking for an alternative to this. Share. Define an entry-point function named findNearestCentroid that accepts centroid positions and new data, and then find the nearest cluster by using pdist2. . ^2 computes the distance matrix. . vector. My one-line implementation of both MATLAB's pdist and pdist2 functions which compute the univariate (pdist) or bivariate (pdist2) Euclidean distances between all pairs of input observations. Sign in to answer this question. Learn more about matrix manipulation, distance, pdist2, matlab function, indexing, matrix, arrays MATLAB I was wondering if there is a built in matlab fucntion that calculates the distance between two arrays that don't have the same column number like in pdist2? I am using pdist to calculate euclidian distances between three dimensional points (in Matlab). 8322 268. I would like to use the command pdist2 in order to compute distance between two geographical coordinates. Y = pdist (X, 'canberra') Computes the Canberra distance between the points. This is the code which runs only on smallish graphs (not hundreds of thousands):pydist2 is a python library that provides a set of methods for calculating distances between observations. MATLAB's custom distance function example. For code generation, define an. The distance between each sample in A and each sample in B can be calculated as follows: First, define a matrix D of size 75x50, s. %. Function File: pdist2 (x, y) Function File: pdist2 (x, y, metric) Compute pairwise distance between two sets of vectors. pairwise distance between rows of matrix A and B. D = pdist2 (X,Y) returns a matrix D containing the Euclidean distances. The most efficient pairwise distance computation. I make a calcul between each point : Distance = pdist2 (X,X); But sometimes I have a problem of memory. dbscan returns the cluster indices and a vector. This norm is also. . %. Let us create a matlab script called speedtest. output D is a 2D matrix with ij entry giving distance between ith row of A and jth row of B. This distance represents how far y is from the mean in number of standard deviations. Go to MATLAB > Preferences > Workspace and ensure the Maximum array size limit is set to 100%. Edit. If observation i or j contains NaN values, the function pdist returns NaN for the pairwise distance between i and j. I have to find the distances between the values in matrix 1 and matrix 2. Rows of X and Y correspond to observations, That is, it works on the ROWS of the matrices. Then execute 'memory' command in the Command Window and send the output. Function File: pdist2 (x, y) Function File: pdist2 (x, y, metric) Compute pairwise distance between two sets of vectors. clc; % Clear the command window. mat file if you need more help. Each row of both matrices identifies a point in 2D space. % accept a matrix ZJ with an arbitrary number of observations. For example instead of @dist(ZI,ZJ) I should send something like @dist(ZI,ZJ,PD) which PD is a parameter (a matrix). tic; d2 = pdist2 (p1,pn); t2 (p) = toc; end. Larger values indicate high distance; - Euclidean similarity, which vary in the range of [0 : 1]. Pass Z to the squareform function to reproduce the output of the pdist function. e.