One way is to call regionprops() to get the centroids of the two blobs. I am using the fitrgp() to fit a Gaussian Regression model to generated data. Ultimately, the idea is that all the sparse. The distance metric to use. The biggest distance using pdist2() will be from one end of the line to the opposite end of the other line. 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. D = pdist2 (X,Y) returns a matrix D containing the Euclidean distances. 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 j. , (2, , corresponds to the distance between objects. 下载并在您的桌面端上安装。. Return the Cholesky decomposition, L * L. 判别分析时,通常涉及到计算两个样本之间的距离,多元统计学理论中有多种距离计算公式。MATLAB中已有对应函数,可方便直接调用计算。距离函数有:pdist, pdist2, mahal, squareform, mdscale, cmdscale. You do that using pdist and then squareform: kernel = @ (X,sigma) exp ( (-squareform (pdist (X,'euclidean')). e. Learn more about mahalanobis, mahal, pdist2, pairwise, difference, versus . We will first introduce the API through Spark’s interactive shell (in Python or Scala), then show how to write applications in Java, Scala, and Python. example. Rows of X and Y correspond to observations, and columns correspond to variables. pydist2 is a python library that provides a set of methods for calculating distances between observations. In the case of the manual method you are using the i index in both of them. It compares row 1 of A with row 1 of B (Z(1,1)), then row 1 of A with row 2 of B (Z(1,2) and Z(2,1)), etc. The Chebyshev distance between two n-vectors u and v is the maximum norm-1 distance between their respective elements. Use kmeans to create clusters in MATLAB® and use pdist2 in the generated code to assign new data to existing clusters. minDistance = 0. @Image Analyst Hello, I tried to find the minimum distance bewteen two objects as per the code you provided on a similar post- 'test3. If you found the line, make a linear interpolation between (i, and i+1) to find the exact (lat/long) intersection. Load the patients data set. ^2). normal,'jaccard'); end. PDIST2 Pairwise distance between two sets of observations. between each pair of observations in the MX-by-N data matrix X and. No account? Create one!Knight Moves: Directed by Carl Schenkel. Copy. Note that the. Nowadays you are probably better of using Matlabs fast compiled version, pdist2; which is about 200% faster when the number of vectors are large. m' but I am unable to find the distance. % Autor: Ana C. 8197976955836 . D = pdist2 (X,Y) returns a matrix D containing the Euclidean distances. e. Start at the beginning of border poly point 0: Find the line where border [i]. If so, the hypot function would work best. It will give you the best groups in aggregate that are farthest away though it's possible some from group1 are closer to some points in group2 that you'd prefer. the first pdist2 works fine, any help would be appreciated 0 Comments. Pass a single point for each of the first two arguments to pdist2 and the result will be a single distance. 2. 获取定价信息. The loop is faster, because Matlab have to access the three used arrays X, Y and d6 locally only. If pdist2 is only fast because it's compiled, then your probably best served by just using it and then squaring the result, since squaring a large number of values is something Matlab does pretty efficiently anyway. This function computes the M-by-N distance matrix D where D(i,j) is the distance between X(i,:) and Y(j. Saltar al contenido. > In pdist2 (line 253) In ExhaustiveSearcher/knnsearch (line 235) In knnsearch (line 154) In internal. Matlab 距离函数pdist pdist2. You can specify DistParameter only when Distance is 'seuclidean', 'minkowski', or. Let X be an m-by-p matrix representing m points in p-dimensional space and Y be an n-by-p matrix representing another set of points in the same space. 这些特征描述了一个人的基本特性,通过身高,体重,我们想象一. D = pdist2 (X,Y,Distance,DistParameter) returns the distance using the metric specified by Distance and DistParameter. How to separately compute the Euclidean Distance in different dimension? 2. Thank you! I tried this, and it didn't quite work for me because I didn't make. % ZJ is an m2-by-n matrix containing multiple observations. pdist2 Pairwise distance between two sets of observations. 0. Create a matrix with three observations and two variables. Vote. % pairwise mahalanobis distance with pdist2() E = pdist2(X,Y,'mahalanobis',S); % outputs an 50*60 matrix with each ij-th element the pairwise distance between element X(i,:) and Y(j,:) based on the covariance matrix of X: nancov(X) %{ so this is harder to interpret than mahal(), as elements of Y are not just compared to. Theme. caseread. knnsearch finds euclidean distance by default. Find more on Graphics Object Programming in Help Center and File Exchange. You can specify DistParameter only when Distance is 'seuclidean', 'minkowski', or. Learn more about TeamsAccepted Answer: Star Strider. squareform returns a symmetric matrix where Z (i,j) corresponds to the pairwise distance between observations i and j. With this, the proposed method and pdist2 appear to be very close (and perhaps pdist2 is faster in some regimes). U = triu (A) returns the upper triangular portion of matrix A. Use pdist2 to find the distance between a set of data and query points. I have a matrix. More precisely, the distance is given by. Answers (2) The file getIpOptions. % Learning toolbox. distfun must. distfun must. pydist2 is a python library that provides a set of methods for calculating distances between observations. Contribute to guy531/keystone development by creating an account on GitHub. 代わりにpdist2という関数があります。 こちらは、2つのベクトルの距離を計算しますが、プロパティで距離のタイプを選ぶことができてその中にマハラノビス距離があります。 scipy. I have some matlab code as follow, constructing KNN similarity weight matrix. If you need to create a list with the indeces, see the method below to avoid loops, since that was the real time-consuming part of your code, rather than the distance method itself. Rik on 12 Oct 2023 at 19:13 I don't expect the performance to be great, but you can use the option of specifying the distance calculation function. tblread. Function File: pdist2 (x, y, metric) Compute pairwise distance between two sets of vectors. For example, you can find the distance between observations 2 and 3. octave pdist (pairwise distance) 3. I am looking for an alternative to this. mat file and we'll show you how you can use pdist2() to find close points. Copy. Learn the Essentials, Build Skills. Copy. D can also be a more general dissimilarity vector or matrix that conforms to the output format of pdist or pdist2, respectively. Pass Z to the squareform function to reproduce the output of the pdist function. y = squareform (Z)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. TagsIt should be as simple as using two nested for loops but I can't get anything to make sense of it. rema on 16 Feb 2023. to see if you have multiple pdist2, and use pathtool to make sure that the Statistics Toolbox one is earlier on your search path. Learn more about custom distance function, pdist, pdist2, @distfun, divergence, kl divergencescipy. NaN NaN NaN NaN 1 2 2 NaN 3 1. Free MATLAB and Simulink learning resources include interactive online courses, documentation and code examples, and how-to videos on product capabilities. where u ⋅ v is the dot product of u and v. Viewed 434 times 0 I'm trying to compare the histogram of an image (hsv) with a cell array that contains the histograms of other images in order to find out the closest matches. m","path":"FastMICE_ConsensusFunction. In this project, we are going to calculate the camera projection matrix and fundamental matrix. Sign in to comment. Try something like E = pdist2 (X,Y-mean (X),'mahalanobis',S); to see if that gives you the same results as mahal. If you are getting the matrices as an output from some code, I strongly recommend you directly store them. D = PDIST2(X,Y) returns a matrix D containing the Euclidean distances between each pair of observations in the MX-by-N data matrix X and MY-by-N data matrix Y. The. % accept a matrix. In human motion analysis, a commond need is the computation of the distance between defferent point sets. 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. %. remoteBlockExecutionPlain (line 49) In spmdlang. For further examples and tests, run. Goncalves. 1. D is an MX-by-MY matrix, with the (I,J) entry equal to distance between observation I in X and. spatial. Application of Face Detection. Show us your code so we can confirm it. % n = norm (v) returns the Euclidean norm of vector v. Then pdist2 should work. Categorizing query points based on their distance to points in a training data set can be a simple yet effective way of classifying new points. y = squareform (Z)pdist2 は、Y 内の各観測値について X 内の観測値すべてに対する距離値を計算して比較することにより、最小の 2 つの距離を求めます。 そして、D の各列に格納されている距離を昇順で並べ替えます。I には、D 内の距離に対応する X 内の観測値のインデックスが格納さ. pydist2 is a python library that provides a set of methods for calculating distances between observations. I thought ij meant i*j. Pelajar UM on 15 Nov 2021. 1. % Isolate data that are within a square around the circle. Regards, Bhavya PDIST2 Pairwise distance between two sets of observations. For each observation in Y, PDIST2 finds the K smallest or largest distances by computing and comparing the distance values to all the observations in X. D = pdist2 (X,Y,Distance,DistParameter) returns the distance using the metric specified by Distance and DistParameter. - GitHub - nolanbconaway/pairdist: A MATLAB function to compute weighted pairwise distances. 特征,可以认为是描述事物的一个特性。. squareform returns a symmetric matrix where Z (i,j) corresponds to the pairwise distance between observations i and j. I'm trying to use the pdist2 function and keep getting this error: "??? Undefined function or method 'pdist2' for input arguments of type 'double'" The 'double' part changes depending on what data. example. Walter Roberson on 7 Jun 2017. The most efficient pairwise distance computation. I call this function from a different script HW3. 82215. The attacks. The gray level is the numerical valuke of the pixel. 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 j. % Learning toolbox. The point is that one of my main functions is to get the distance between 2 particles, and sometimes it returns 0 even if the particles are not that close. 如果输入的是冗余的距离矩阵,将返回简洁的距离矩阵. y = squareform (Z)That's a no-no for 'pdist2'. You can specify DistParameter only when Distance is 'seuclidean', 'minkowski', or. // Determinar la mínima distancia dadas dos. 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 was told that by removing unnecessary for loops I can reduce the execution time. Copy. CHAPTER ONE PYDIST2 pydist2isapythonlibrarythatprovidesasetofmethodsforcalculatingdistancesbetweenobservations. 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. But pdist2 might have a lot of overhead. Follow answered Jan 14, 2014 at 17:10. v (N,) array_like. sum (X ** 2, axis = -1) K = ne. Please show us how you are storing the line data, a relevant sample of code etc to make your problem clearer. pdist2 computes the distance between all pairs of points of the two inputs. The most efficient pairwise distance computation. Unlike pdist, pdist2 takes two sets of data X = { x i } i = 1 m and Y = { y j } j = 1 m and compute m n number of pairwise distances for all i and j. Y = pdist (X, 'canberra') Computes the Canberra distance between the points. The pairwise distances are arranged in the order (2,1), (3,1), (3,2). The result comes with so much noise and i cannot see the result of length measurement. 78874218621840] Your third party file c:\toolbox\classify\pdist2. m. 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. 93847 0. on 16 Feb 2023. mat file and we'll show you how you can use pdist2() to find close points. Use pdist2 to find the distance between a set of data and query points. To do that you'd have to use the algorithm I outlined. Rows of X and Y correspond to observations, That is, it works on the ROWS of the matrices. of matlab I do not have the pdist2 function. See Notes for common calling conventions. Is there any function in Matlab that can take two vectors (not necessarily of the same size) and apply a binary function on every pair of the vector's elements resulting in a matrix n1xn2, where n1 and n2 are the lengths of the input vectors?Note: If you use the live script file for this example, the clustf function is already included at the end of the file. 1 − u ⋅ v ‖ u ‖ 2 ‖ v ‖ 2. I have two sets of data phi1 and phi2, and I'd like to know what the pairwise distances are for these two sets. file began to complain that "??index=linspace (1,size (points,1),size (points,1)); is the strangest way I've seen of simply doing: Theme. Learn more about for loop, matrix, matlab, pdist MATLAB. m. NaN NaN NaN NaN 1 2 2 NaN 3 1. Fit a GPR model using the custom kernel function, kfcn . You can use the pdist2 MATLAB / Octave function to calculate pairwise distances between two sets of observations. Runtime: less than a minute. See Notes for common calling conventions. Distance MetricsX의 관측값 i 또는 Y의 관측값 j가 NaN 값을 포함하는 경우, 함수 pdist2는 i와 j 간의 쌍별(Pairwise) 거리로 NaN을 반환합니다. 대량의 관측값을 사용하는 경우에는. Suppose we have two groups with means and , Mahalanobis distance is given by the following. Email. computes the Euclidean distance between pairs of objects in . 获得无限制的在线版访问权限。. Link. Not efficient, but a fun alternative :) – Divakar. ') %//' %// Use DIFF to get a logical array of repetitions and %// use. Answers (1) Two possibilities come to mind, one being knnsearch (link), and the other being pdist2 (link). 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. Copy. Y = cdist(XA, XB, 'jaccard'). m. Categories MATLAB Graphics Graphics Objects Graphics Object Programming. For code generation, define an. tic; d2 = pdist2 (p1,pn); t2 (p) = toc; end. If you used XData and YData options in imshow(), then pdist2 should give the output in microns already. We bring some examples of bigram association calculations from Manning and Schutze’s SNLP, 2nd Ed. You can use various metrics to determine the distance, described next. comparison of two histograms using pdist2. D = pdist2 (X,Y) returns a matrix D containing the Euclidean distances. When working with a large number of. 0. between each pair of observations in the MX-by-N data matrix X and. d(u, v) = max i | ui − vi |. Distance Metrics 장치의 메모리를 절약하기 위해 각각 kmeans와 pdist2를 사용하여 훈련과 예측을 분리할 수 있습니다. Vectorization speed-up for row-wise norms of two matrixes. Fowzi barznji on 16 Mar 2020. Use cellfun in combination with strfind and isempty or isequal directly. pdist2 Pairwise distance between two sets of observations. However, manually defining the cell array is a limitation here. 0 Comments. Then sqrt() requests the complete arrays again and. pdist2 computes the distances between observations in two matrices and also returns a distance matrix. D = pdist2 (X,Y,Distance,DistParameter) returns the distance using the metric specified by Distance and DistParameter. Copy. @all, thanks a lot. ) Y = pdist (X,'. spikeTimes = rand (numPoints2, 1) % Sample data. 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 j. The equivalent. Teams. 1. Rows of X and Y correspond to observations, and columns correspond to variables. Sorted by: 8. is there an alternative to pdist2 that calculates the distance between a matrices with different column numbers. The primary class definition contains a signature for the function. function Distance = euclidean (x,y) % This function replaces the function pdist2 available only at the Machine. D = pdist2 (X,Y) returns a matrix D containing the Euclidean distances. longitude >= loc. Copy. Any help. There are two main classes: pdist1 which calculates the pairwise distances between observations in one matrix and returns a distance matrix. You can specify DistParameter only when Distance is 'seuclidean', 'minkowski', or. d(u, v) = max i | ui − vi |. which -all pdist2. When working with a large number of. Categorizing query points based on their distance to points in a training data set can be a simple yet effective way of classifying new points. example. The dot of the i will have a lower y value of its centroid than the body of the i. sir is there any function to reduce row size. But pdist2 might have a lot of. pdist_oneLine. %. D = pdist2(___,Name,Value)使用名称-值对参数之一指定附加选项。'Smallest'或'Largest'除了以前语法中的任何参数之外。 例如, D = pdist2(X,Y,Distance,'Smallest',K)指定的度量计算距离。Distance并返回K与观测的最小成对距离X中的每一次观察Y按升序排列。 This is a very interesting suggestion and comparison. Technical support available in 10 languages via telephone, email, and the web. kmedoids can use any distance metric supported by pdist2 to cluster. During a chess tournament, grand master. How to find closest Lat/Lon on a grid to an. See inline comments for details (some of which are important). for low dimensional points (3 in this example) it should be more efficient to. dist =pdist2(color_table, reshape(im, [h*w, 3])); color_table is a 2D array. Note that the. 可以这样理解 D 的生成:首先生成一个 X 的距离方阵,由于该方阵是对称的,且对角线上的元素为0,所以取此方阵的下三角元素. % Learning toolbox. 0. % ZI is a 1-by-n vector containing a single observation. Sign in to answer this question. You can specify DistParameter only when Distance is 'seuclidean', 'minkowski', or. Computes the Euclidean distance between rows of two matrices. I'd recommend you always use size (points, 1) as length would return the number of columns if for some reason you only had 1 or 2 points. This function has been. , (2, , corresponds to the distance between objects. To check the existence of a local variable: if 'myVar' in locals (): # myVar exists. D = pdist2 (F (i). remoteBlockExecution (line 15) Worker 11: Warning: Converting input data to double. There will only be one smallest distance. Improve this answer. After reading through the documentation, it is a very versatile tool. I'm having some trouble in calculating the Mahalanobis Distance between a pair of objects. axis: Axis along which to be computed. 判别分析时,通常涉及到计算两个样本之间的距离,多元统计学理论中有多种距离计算公式。MATLAB中已有对应函数,可方便直接调用计算。距离函数有:pdist, pdist2, mahal, squareform, mdscale, cmdscale. Nov 8, 2013 at 9:26. s_p_dist_jaccard=pdist2(s,p, 'jaccard') = 0. Now, it is confirmed that I do not have a license. . mahal. 0. Function File: pdist2 (x, y, metric) Compute pairwise distance between two sets of vectors. b = load (fullFileName); %puts it into an array, size varies as the loop runs through the 32 files!!! FileRMSdata = b. %. I want the haversine distance to be more specific. as returned without any edit or the like -- in contrast what you actually show is two other variables:I had a class defined in an @folder, with functions in their own files. Default is None, which gives each value a weight of 1. spatial. E=pdist2(X,Y-mean(X),'mahalanobis',S). , is a vector of length ), (2,3),. These code has been written as part of the project I have performed in image processing course some time ago. 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 (. This module contains two main interfaces which provides the following functionalities: pdist1 calculates the pairwise distances between points in one vector and returns a vector which represents the distance between the observations. But of course you should plug in your actual data and results will probably be better. distfun must accept a matrix XJ with an arbitrary number of rows. With Octave 5. Learn more about histogram comparison, image comparison, image segmentation, distance comparison, chi-square Image Processing Toolbox hi, I am having two Images I wanted compare these two Images by histograms I have read about pdist that provides 'chisq' but i think the way i am doing. This can be modified as necessary, if one wants to apply distances other than the euclidean. casewrite. The double-loop above has O(N²) complexity. I have a vector X which contain x and y value in column 1 and 2 respectively. Description. The logical negation ~ gives 1 for those pairs of rows, and 0 otherwise. D = pdist2 (X,Y,Distance) returns the distance between each pair of observations in X and Y using the metric specified by Distance. ; Home automation: To maintain security, especially in a home that is. In your example code you compute the distance between two points. For example, you can find the distance between observations 2 and 3. squareform returns a symmetric matrix where Z (i,j) corresponds to the pairwise distance between observations i and j. for i=1:m. Edit. You can specify DistParameter only when Distance is 'seuclidean', 'minkowski', or. m. D = pdist2 (X,Y) returns a matrix D containing the Euclidean distances. pdist1 and pdist2 The library can compute distances between pair of observations in one vector using pdist1, and distances between pair of observations in two vectors using pdist2. . I use the pdist2 function to calculate the the distance between the points stored in matricies. D = pdist2(X,Y,@distfun) the custom distance function has to have this header. Instruction to use the function in the files. I want you to clear one thing as I noticed now though I changed bins to 59 but still number of columns in color image remains 1024 only I displayed it on command prompt. 0. pdist and pdist2 can calculate the city block distance. The biggest distance using pdist2() will be from one end of the line to the opposite end of the other line. 判别分析时,通常涉及到计算两个样本之间的距离,多元统计学理论中有多种距离计算公式。MATLAB中已有对应函数,可方便直接调用计算。距离函数有:pdist, pdist2, mahal, squareform, mdscale, cmdscale 主要介绍pdist2 ,其它可参考matlab help D = pdist2(X,Y)D = pdist2(X,Y,distance)D = pdist. 尝试类似的方法,比如. However, generally the manual calculation is slightly faster or. % n = norm (v) returns the Euclidean norm of vector v. Read tabular data from an ascii file. 'cosine') varies between 0 and 2. I suppose x and y are matrixes, so you are using pdist2 to compute the distance between the observation i (from x(i)) and j (from y(j)). For example the not weighted RBF and sigmoid kernel can be computed as follows: K_rbf = exp (-gamma . If you have the Statistics Toolbox: Response = ~(pdist2(index, A)); or: Response = ~(pdist2(index, A, 'hamming')); This works because pdist2 computes the distance between each pair of rows. pdist_oneLine. Parameters: XAarray_like. n = norm (A) returns the 2 -norm of symbolic matrix A . 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. pdist2 supports various distance metrics: Euclidean distance, standardized Euclidean distance, Mahalanobis distance, city block distance, Minkowski distance, Chebychev distance, cosine distance, correlation distance,. Clustering. The matrix must be positive definite which is not the same as having positive entries. Q&A for work. distance. 2种计算方式,一种直接利用pdist计算,另一种. One matrix has 2 sets of coordinates. . I'm sorry, you are correct. This norm is also. pdist2 calculates the distances between observations in two vectors with one of the following methods: manhattan: The L1 distance between two vectors P and Q is defined. Create distance matrix from the result of pdist. 试用 MATLAB、Simulink 和 80 多种产品。. For each and (where ), the metric dist (u=X [i], v=X [j]) is computed and stored in entry ij. Copy. . between each pair of observations in the MX-by-N data matrix X and. Different behaviour for pdist and pdist2. Two sets of matrix. This norm is also. pdist1 and pdist2 The library can compute distances between pair of observations in one vector using pdist1, and distances between pair of observations in two vectors using pdist2. 7 (numpy)? 1. . a must be Hermitian (symmetric if real-valued) and positive-definite. Rows of X and Y correspond to observations, That is, it works on the ROWS of the matrices. . comparing histograms with matlab through pdist2. It measures the separation of two groups of objects. Show -1 older comments Hide -1 older comments. I simply call the command pdist2(M,N). Rik on 12 Oct 2023 at 19:13 I don't expect the performance to be great, but you can use the option of specifying the distance calculation function. m should be stored in the directory identified below. keystone. I have two data sets of different sizes, one of which is a nx2 matrix of latitude, longitude. Use pdist2 with 'hamming' distance [D I] = pdist2( A, B, 'hamming', 'Smallest', 1 ); Share. MATLAB's custom distance function example. D = pdist2(X,Y); 用法:设X为一个M行N列的矩阵,Y为一个P行Q列的矩阵,则函数的返回值D为一个M行P列的矩阵。 pdist2计算X中任意一个行向量与Y中任意一个行向量的距离,默认采用欧氏距离公式。dist = pdist2(d,centroids,distance); % distance between all data points and centroids I'd like to mention that I used matlab in system with windows 8 and following configuration :中的每个点减去. % generate some example data N = 4 M. pdist2() is going to return a 2D array that is number of rows in color_table by number of rows in the reshape()For a proyect I want to use pdist2 (Pairwise distance between two sets of observations) but I need an specific function. Teams. numexpr is a python package that allows for efficient and parallelized array operations on numpy arrays. for one run, the function was called upon 27,245 times. Matlab 距离函数pdist pdist2. In Matlab there exists the pdist2 command. . fullFileName = fullfile (myfolder, baseFileName); %loads the data for the file that I want to compare to baseline neutralRMS. D = pdist2 (X,Y,@CalcDist) function D2=CalcDist (ZI,ZJ) % calculation of distance. end. Copy. example. But in your case the matrix has only rank D = PDIST2 (X,Y,DISTANCE, 'Largest',K) returns the K largest pairwise distances sorted in descending order. Very clever - I wouldn't have thought about the pdist2 function (+1).