Computes the Euclidean distance between rows of two matrices. axis: Axis along which to be computed. pydist2 is a python library that provides a set of methods for calculating distances between observations. I studied about pdist2 function , I used it : Theme. I would like to use the command pdist2 in order to compute distance between two geographical coordinates. I hope that is a little clearer. Compute the Euclidean distance between pairs of observations, and convert the distance vector to a matrix using squareform. . . md","path":"README. between each pair of observations in the MX-by-N data matrix X and. I have two data sets of different sizes, one of which is a nx2 matrix of latitude, longitude. d(u, v) = max i | ui − vi |. Sorted by: 4. Y = pdist (X, 'canberra') Computes the Canberra distance between the points. I was told that by removing unnecessary for loops I can reduce the execution time. Returns: cityblock double. 的样本平均值. 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. Sign in to comment. I don’t know what format your latitude and longitude arrays are (I assume decimal degrees rather than ‘d:m:s’). X. %. The function you pass to pdist must take . Hot Network Questionsisequal (k1,k2) nnz (k1-k2) The results k1 and k2 are identical (in some cases not, due to the internal numerical properties of pdist2). D = pdist2 (X,Y) returns a matrix D containing the Euclidean distances. We would like to show you a description here but the site won’t allow us. Sign in to comment. 试用 MATLAB、Simulink 和 80 多种产品。. comparing histograms with matlab through pdist2. 0000 %# Note that I get different results than your example!Basically that bsxfun(@eq translates to pdist2()==0, which you might have used before. 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 function Distance = euclidean (x,y) % This function replaces the function pdist2 available only at the Machine. Given the matrix mx2 and the matrix nx2, each row of matrices represents a 2d point. Show -1 older comments Hide -1 older comments. distfun must accept a matrix XJ with an arbitrary number of rows. kmeans를 사용하여 MATLAB®에서 군집을 생성하고 생성된 코드에서 pdist2를 사용하여 기존 군집에 새 데이터를 할당합니다. Q&A for work. Computes the distance between m points using Euclidean distance (2-norm) as the distance metric between the points. This is unreproducible for me as well. % Autor: Ana C. I'm trying to calculate Haversine distance but I don't know how to apply the funtion in this case. Pdist2 inside for. Answers (2) The file getIpOptions. The matrix must be positive definite which is not the same as having positive entries. i. e. distance. D= pdist2(X,Y,Distance,DistParameter)指定的度量返回距离。You can use the function NCHOOSEK to generate a set of indices into X and build your matrix in the following way: >> X = [100 100; 0 100; 100 0; 500 400; 300 600]; %# Your sample data >> D = pdist(X,'euclidean')' %'# Euclidean distance, with result transposed D = 100. D = pdist2 (X,Y,Distance) returns the distance between each pair of observations in X and Y using the metric specified by Distance. This instuctional code demonstrates validation by posterior agreement for connectivity-based cortex parcellation of diffusion weighted imaging data. D = pdist2 (X,Y) returns a matrix D containing the Euclidean distances. Sir, actually the block[50 X 6] contains 'minutiae' information which contains the following data in columns [X, Y, CN, Theta, Flag, 1]and rows contains number of minutiae information on the dorsalhandvein. Instruction to use the function in the files. squareform: Interchange between distance matrix and distance vector formats. The ability to purchase add-on products. Not efficient, but a fun alternative :) – Divakar. cholesky (a) [source] # Cholesky decomposition. 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. Rows of X and Y correspond to observations, That is, it works on the ROWS of the matrices. D = pdist2 (X,Y,Distance) returns the distance between each pair of observations in X and Y using the metric specified by Distance. X = [x1, x2] I am wondering how to construct a kernel function in 2D for fitrgp(X, y, 'KernelFunction', kfcn) In 1D input c. The pairwise distances are arranged in the order (2,1), (3,1), (3,2). D = pdist2 (X,Y,Distance,DistParameter) returns the distance using the metric specified by Distance and DistParameter. Show 2 older comments Hide 2 older comments. The logical negation ~ gives 1 for those pairs of rows, and 0 otherwise. The cascade object detector uses the Viola-Jones algorithm to detect people’s faces, noses, eyes, mouth, or upper body. 可以这样理解 D 的生成:首先生成一个 X 的距离方阵,由于该方阵是对称的,且对角线上的元素为0,所以取此方阵的下三角元素. Distance Metrics 장치의 메모리를 절약하기 위해 각각 kmeans와 pdist2를 사용하여 훈련과 예측을 분리할 수 있습니다. [D,I] = pdist2(X, X, 'squaredeuclidean', 'Smallest', k+1); D = D < threshold; W = zeros. D = pdist2 (X,Y,Distance) returns the distance between each pair of observations in X and Y using the metric specified by Distance. Rows of X and Y correspond to observations, That is, it works on the ROWS of the matrices. mahal. 2. After reading through the documentation, it is a very versatile tool. Matlab 距离函数pdist pdist2. longitude >= loc. Goncalves. H, of the square matrix a, where L is lower-triangular and . Learn more about cosine similarity, cosine distance, jaccard similarity, jaccard distance, similarity, dissimilarity, bin counts, histogram, histcount, pdist, pdist2, distance, vectors, arrays I would like to assess the similarity between two "bin counts" (that I previously derived through the "histcounts" function), by using the "pdist2. . mat file and we'll show you how you can use pdist2() to find close points. / (2*sigma^2)); K = [ (1:size. It shows a path (C:Program FilesMATLAB. Warning: Converting input data to single. It computes the distances between rows of X. 这里 D 要特别注意,D 是一个长为m (m–1)/2的行向量. Learn more about euclidean, minimum distance, pdist, pdist2, distance, minimum Hi, I am trying to make a function to find minimum distance between my random points and a point (0,0) and plot the distance as a line crossing from the (0,0) to the one of the closest rand pt. particle. The matrix I contains the indices of the observations in X corresponding to the distances in D. D = pdist2 (X,Y,Distance,DistParameter) returns the distance using the metric specified by Distance and DistParameter. In your example code you compute the distance between two points. These code has been written as part of the project I have performed in image processing course some time ago. One possible way to define a kernel. . The points are grouped into two clusters. Mapping Toolbox supports a complete workflow for managing geographic data. Hay una función correspondiente en Matlab, que es conveniente para llamar al cálculo. Modified 8 years, 5 months ago. The Hamming distance between two vectors is the percentage of the vector components that differ. Select a Web Site. D = pdist2 (X,Y) returns a matrix D containing the Euclidean distances. You can specify DistParameter only when Distance is 'seuclidean', 'minkowski', or. Given X = randu(3, 2), Y = randu(3, 2), where each row stores an observation (x, y). I am most confused as how to compile each coordinate set so that each point is assigned a space in 2-D. @all, thanks a lot. cityblockSimilarity. This function has been. Theme Copy D = pdist2 (X,Y,@CalcDist) function D2=CalcDist (ZI,ZJ) % calculation of distance % % ZI is a 1-by-n vector containing a single observation. D = pdist2 (X,Y,Distance,DistParameter) returns the distance using the metric specified by Distance and DistParameter. Use cellfun in combination with strfind and isempty or isequal directly. What I mean is, the way the distance between the two bones in one image was found, I need to find the distance between the two bones for all these images(420 images). computes the distance between objects in the data matrix, , using the method. 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. PDIST2 introducido principalmente, otros pueden. D = pdist2 (X,Y,@CalcDist) function D2=CalcDist (ZI,ZJ) % calculation of distance. 尝试类似的方法,比如. Mahalanobis distance is also called quadratic distance. D = pdist2 ( X,Y, Distance, DistParameter) 指定的度量返回距离。. Well, pdist2 finds the 8 nearest neighbors of every point (x0,y0) and if any of the neighbors is at a distance of >1 than (x0,y0) is classified as belonging to the sparse region, and is discarded from the list. Answers (1) Two possibilities come to mind, one being knnsearch (link), and the other being pdist2 (link). 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. It computes the distances between rows of X. pdist2 computes the distances between observations in two matrices and also returns a distance matrix. Because symbolic variables are assumed to be complex by default, the norm can contain unresolved calls to conj and abs. After the preliminaries are out of the way, pdist2 has the following-- % Call a mex file to compute distances for the build-in distance measures % on non-sparse real float (double or single) data. 45694. Very clever - I wouldn't have thought about the pdist2 function (+1). The most efficient pairwise distance computation. - GitHub - nolanbconaway/pairdist: A MATLAB function to compute weighted pairwise distances. 如果输入的是冗余的距离矩阵,将返回简洁的距离矩阵. However, generally the manual calculation is slightly faster or. distfun must. The. cityblockSimilarity. out = 1×10. Create distance matrix from the result of pdist. NaN NaN NaN NaN 1 2 2 NaN 3 1. I am getting the following error: Theme. I simply call the command pdist2(M,N). pdist2 supports various distance metrics: Euclidean distance, standardized Euclidean distance, Mahalanobis distance, city block distance, Minkowski distance, Chebychev distance, cosine distance, correlation distance, Hamming distance, Jaccard distance, and Spearman distance. It computes the distances. This repository contains the MATLAB scirpts, which perform power analysis attacks on the AES-256 RSM (v4) in DPA contest v4. normal,'jaccard'); end. pdist and pdist2 can calculate the city block distance. between each pair of observations in the MX-by-N data matrix X and. [D,I] = pdist2 ( ___) also returns the matrix I. Distance 和 DistParameter 。. Regards, BhavyaD = pdist2 (X,Y,@CalcDist) function D2=CalcDist (ZI,ZJ) % calculation of distance. % n = norm (v) returns the Euclidean norm of vector v. Thank you! I tried this, and it didn't quite work for me because I didn't make. mahal() function. These are the top rated real world Python examples of utils. 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. It's hard to tell without knowing what dtw2 is. I want to use the Manhattan Distance and I have a definition for it, so how the heuristic for it should be calculated, but I am not sure if it is correct. MY-by-N data matrix Y. If K is greater than MX, PDIST2 returns an MX-by-MY distance matrix. I have a vector X which contain x and y value in column 1 and 2 respectively. pdist2 equivalent in MATLAB version 7. For example, you can find the distance between observations 2 and 3. between each pair of observations in the MX-by-N data matrix X and. figure. 0. 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 : 中的每个点减去. 的样本平均值. In the case of a symmetric matrix this means that all eigenvalues must be positive. % accept a matrix ZJ with an arbitrary number of observations. In pdist2 (line 219) In extractFeaturesU (line 93) The code line that is returning a warning message is: [distance, position] = sort (pdist2 (double (repmat (featuresA, size (xPoints, 1))), featuresB), 2, 'ascend'); The part of the code containing the above line is displayed below. D = pdist2(color_table, reshape(im, [ht*wid, 3])); end. Contribute to guy531/keystone development by creating an account on GitHub. Copy. Description. of matlab I do not have the pdist2 function. For example, you can find the distance between observations 2 and 3. example. ^2). This function computes the m-by-n distance matrix D where D (i,j) % is the distance between X (i,:) and Y (j,:). m. s_p_dist_jaccard=pdist2(s,p, 'jaccard') = 0. Z (2,3) ans = 0. Y = pdist (X, 'canberra') Computes the Canberra distance between the points. lat<= loc. However, I use this matrix in a loop like this : for i:1:n find (Distance (i,:) <= epsilon);. numpy. With Octave 5. 0. Only in mahal you are comparing each point of your sample set to the points of the reference distribution, while in pdist2 you are making pairwise comparisons based. In case it's not faster, it's at least a lot easier to understand. For a dataset made up of. I use the pdist2 function to calculate the the distance between the points stored in matricies. 0. . Meta. So, do you know how to make the calcul inside the. License: GNU General Public License v3 (GPLv3) Author: Benjamin Paassen Tags levenshtein-distance, dynamic-time-warping, sequence-edit-distance, sequence-alignment, tree-edit-distance, algebraic-dynamic-programmingmatlab中自带的计算距离矩阵的函数有两个pdist和pdist2。前者计算一个向量自身的距离矩阵,后者计算两个向量之间的距离矩阵。基本调用形式如下: D=pdist(X) D=pdist2(X,Y) 这两个函数都提供多种距离度量形式,非常方便,还可以调用自己编写的距离. % Learning toolbox. The City Block (Manhattan) distance between vectors u and v. Y = cdist(XA, XB, 'hamming'). There are two main classes: pdist1 which calculates the pairwise distances between observations in one matrix and returns a distance matrix. Security purpose: Face recognition is turning out to be the most common method to maintain the security of the individual/organization. Rows of X and Y correspond to observations, That is, it works on the ROWS of the matrices. An m by n array of m original observations in an n-dimensional space. Pdist2 inside for. Currently avaliable codes in FEX are also insufficient as they can only compute (squared. % Learning toolbox. Everything compiles fine without errors etc. 82215. We can use it as follows to perform the same computation as above: import numpy as np import numexpr as ne X_norm = np. import numpy as np from Levenshtein import distance from scipy. There are two main classes: pdist1 which calculates the pairwise distances. 获取定价信息. How can I compute the above weighted kernels efficiently in Matlab?scipy. Please show us how you are storing the line data, a relevant sample of code etc to make your problem clearer. A distance metric is a function that defines a distance between two observations. D = pdist2 (X,Y,@CalcDist) function D2=CalcDist (ZI,ZJ) % calculation of distance. 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. 1. m. 'cosine') varies between 0 and 2. ind = dsearchn (tmpref, tmptar); But knnsearch is tested ⵜ to be faster than dsearchn in this case. I also know that pdist2 can help reduce the time for calculation but since I am using version 7. If you found the line, make a linear interpolation between (i, and i+1) to find the exact (lat/long) intersection. 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. PDIST2 Pairwise distance between two sets of observations. Teams. Inputs are converted to float type. Improve this answer. n = norm (v,p) returns the p -norm of symbolic vector v. I'm making a set of functions in C for simulate a microcanonial ensamble (a periodic-bounded box with N particles with fixed Energy and Volume). distance. {"payload":{"allShortcutsEnabled":false,"fileTree":{"":{"items":[{"name":"README. 1、y = squareform (x) x 是对称的距离矩阵,对角线元素都为0,y=dist. position is a 15x2 matrix, x is 100x2 and basestation is [50 50] but for the second pdist2 it tells me there is a column mismatch even though they all have to columns. Parameters : array: Input array or object having the elements to calculate the distance between each pair of the two collections of inputs. Sorted by: 1. CanberraSimilarity. MATLAB 距离函数及用法. % ZI is a 1-by-n vector containing a single observation. It's too slow right now because there are so many dots. Compute distance between each pair of the two collections of inputs. Fowzi barznji on 16 Mar 2020. 代わりにpdist2という関数があります。 こちらは、2つのベクトルの距離を計算しますが、プロパティで距離のタイプを選ぶことができてその中にマハラノビス距離があります。 scipy. I would like to use the command pdist2 in order to compute distance between two geographical coordinates. Regards, Bhavya PDIST2 Pairwise distance between two sets of observations. Find more on Graphics Object Programming in Help Center and File Exchange. Sorted by: 8. 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. X is a 50*3 matrix, Y is a 60*3 matrix. Pass Z to the squareform function to reproduce the output of the pdist function. I have some matlab code as follow, constructing KNN similarity weight matrix. Feature points (read corners) in images are points that invariant under view changes, zoom, lightening conditions etc. Function File: pdist2 (x, y, metric) Compute pairwise distance between two sets of vectors. I know the distance(lat1,lon1,lat2,lon2) command is the suitable for this but I want to use pdist2 command. . pdist2 Pairwise distance between two sets of observations. This can be done in pdist2. md","contentType":"file"},{"name":"TKDE_Ultra-Scalable Spectral. where is the mean of the elements of vector v, and is the dot product of and . m is interfering with use of the pdist2 from the Statistics toolbox. The distance metric to use. comparison of two histograms using pdist2. Then sqrt() requests the complete arrays again and. Now I remember you have used that matrix multiplication instead of pdist2 beforeFind Nearest Points Using Custom Distance Function. pydist2 is a python library that provides a set of methods for calculating distances between observations. gitattributes","path":". RMSFramesMat; EucDist = pdist2 (neutralRMSdata, FileRMSdata, 'hamming');Each row of both matrices identifies a point in 2D space. distfun must return an m2-by-1 vector of distances d2, whose kth element is the distance between XI. With Codie Lucas Wilbee, Joshua Murray, Frank C. . e. Learn more about for loop, matrix, matlab, pdist MATLAB. Note that the. pdist2 is optimized to return the distance from each of the points in the first argument to each of the points in the second argument, so if you only want one distance then only pass a single point to each. D = pdist2 (X,Y,Distance,DistParameter,'Largest',K) computes the distance using the metric specified by Distance and DistParameter and returns the K largest pairwise distances in descending order. 欧氏距离(Euclidean Distance) 欧氏距离是最易于理解的一种距离计算方法,源自欧氏空间中两点间的距离公式。(1)二维平面上两点a(x1,y1)与b(x2,y2)间的欧. Sign in to answer this question. Every time I want to use pdist2, I get the following error: Undefined function 'pdist2mex' for input arguments of type 'double'. 0 installed and run with flatpak, I can install the statistics package from Octave Forge, and the results are the same as others have shown here: >> D = pdist2 (X, Y) D =. scipy. But of course you should plug in your actual data and results will probably be better. D = pdist2 (X,Y,Distance) returns the distance between each pair of observations in X and Y using the metric specified by Distance. 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. Feb 25, 2018 at 9:36. Utilice kmeans para crear grupos en MATLAB® y utilice pdist2 en el código generado para asignar nuevos datos a grupos existentes. For example the not weighted RBF and sigmoid kernel can be computed as follows: K_rbf = exp (-gamma . The biggest distance using pdist2() will be from one end of the line to the opposite end of the other line. To do that you'd have to use the algorithm I outlined. y = squareform (Z)pdist2 は、Y 内の各観測値について X 内の観測値すべてに対する距離値を計算して比較することにより、最小の 2 つの距離を求めます。 そして、D の各列に格納されている距離を昇順で並べ替えます。I には、D 内の距離に対応する X 内の観測値のインデックスが格納さ. You can also do this using a combination of pdist2 ⬥ and min instead of knnsearch (in line 6). With the knowledge of camera calibration and Epipolar Geometry, we can now improve the result we get from project 2 for keypoints matching. pdist2 Pairwise distance between two sets of observations. cosine. – am304. For the future, try typing edit pdist2 (or whatever other function) in Matlab, in most cases, you will see the Matlab function, which you can then convert to python. Learn more about mahalanobis, mahal, pdist2, pairwise, difference, versus . Share. Ignore that code (I'll delete it) and use this instead: timeStamps = rand (numPoints1, 1) % Sample data. squareform returns a symmetric matrix where Z (i,j) corresponds to the pairwise distance between observations i and j. Theme Copy D = pdist2. I've tried applying the funtion pdist2 with the added argument angdiff but I get the. Sir, actually the block[50 X 6] contains 'minutiae' information which contains the following data in columns [X, Y, CN, Theta, Flag, 1]and rows contains number of minutiae information on the dorsalhandvein. pdist2 Pairwise distance between two sets of observations. Theme. pdist2 supports various distance metrics: Euclidean distance, standardized Euclidean distance, Mahalanobis distance, city block distance, Minkowski distance, Chebychev distance, cosine distance, correlation distance,. U = triu (A,k) returns the elements on and above the kth diagonal of A. mat file and we'll show you how you can use pdist2() to find close points. It computes the distances between rows of X. spatial. ,an},将它们按大小顺序排列,取中间的那个值作为滤波器的输出。 @Lukas Gaßmann Start your own question with your EEG data attached in a . 78874218621840] Your third party file c:\toolbox\classify\pdist2. 1. Centroid, blobMeasurements (j). An m A by n array of m A original observations in an n -dimensional space. . However, even though the number of arguments is correct, I still get the. 使用四个预处理器指令来控制条件编译:. pdist2 Pairwise distance between two sets of observations. for low dimensional points (3 in this example) it should be more efficient to. 计算 X 中各对行向量的相互距离 (X是一个m-by-n的矩阵). Y = cdist(XA, XB, 'jaccard'). My question is why applying the mean-function over the output of pdist2() in c. The most efficient pairwise distance computation. pdist2. A distance function must be of the form . Would you help correcting my. Rows of X and Y correspond to observations, and columns correspond to variables. m. pdist2 computes the distances between observations in two matrices and also returns a distance matrix. pdist2 (P1,P2, 'cityblock'); But in my case, I want to use the columns of my. D = pdist2 (X,Y,Distance) returns the distance between each pair of observations in X and Y using the metric specified by Distance. In human motion analysis, a commond need is the computation of the distance between defferent point sets. MY-by-N data matrix Y. To do that you'd have to use the algorithm I outlined. Otherwise, you need to create the function at the end of your . {"payload":{"allShortcutsEnabled":false,"fileTree":{"classify":{"items":[{"name":"private","path":"classify/private","contentType":"directory"},{"name":"Contents. I have a matrix that looks like this:Description. 0. D = pdist2 (X,Y,@CalcDist) function D2=CalcDist (ZI,ZJ) % calculation of distance. . pdist_oneLine. Matlab-pdist2函数用法. Python pdist2 - 8 examples found. Accepted Answer. Goncalves. For the nearest neighbor distance, the smallest pairwise distance value was chosen for each data point. Use kmeans to create clusters in MATLAB® and use pdist2 in the generated code to assign new data to existing clusters. Pass Z to the squareform function to reproduce the output of the pdist function. % Euclidean / SQUARED Euclidean distance. I don't think it is any faster computing that with hand-written MATLAB code. 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. In Matlab there exists the pdist2 command. Any help. Let's say that the pixel to pixel spacing is 64 microns, and you want the distance between the 34th blob and the 78th blob. If you used XData and YData options in imshow(), then pdist2 should give the output in microns already. function D2 = DISTFUN(ZI,ZJ)This can be done in pdist2. 1 Enlazar Traducir Comentada: Ana Gonçalves el 16 de Feb. of matlab I do not have the pdist2 function. If I answered with something as broad as you have asked, I would say "using diff or subtracting one vector from another". w (N,) array_like, optional. The builtin function `pdist2` could be helpful, but it is inefficient for multiple timeframes data. I'm having some trouble in calculating the Mahalanobis Distance between a pair of objects. Specify the initial values of the kernel parameters (Because you use a custom kernel function, you must provide initial values. La función pdist2 puede usar CacheSize solo cuando el argumento Distance empiece por fast. Copy. spikeTimes = rand (numPoints2, 1) % Sample data. cholesky# linalg. There are two main classes: pdist1 which calculates the pairwise distances between observations in one matrix and returns a distance matrix. 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. pdist2 Pairwise distance between two sets of observations. example. for i=1:m. if i go like this the matrix size increase, so I want to reduce minutiae information which is in row. 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. In human motion analysis, a commond need is the computation of the distance between defferent point sets. m file or add it as a file on the MATLAB® path. Rows of X and Y correspond to observations, That is, it works on the ROWS of the matrices.