All Questions
Tagged with euclidean-distance matlab
90
questions
13
votes
2
answers
5k
views
Efficiently compute pairwise squared Euclidean distance in Matlab
Given two sets of d-dimensional points. How can I most efficiently compute the pairwise squared euclidean distance matrix in Matlab?
Notation:
Set one is given by a (numA,d)-matrix A and set two is ...
11
votes
3
answers
14k
views
How to convert distance into probability?
Сan anyone shine a light to my matlab program?
I have data from two sensors and i'm doing a kNN classification for each of them separately.
In both cases training set looks like a set of vectors of 42 ...
9
votes
3
answers
5k
views
pdist2 equivalent in MATLAB version 7
I need to calculate the euclidean distance between 2 matrices in matlab. Currently I am using bsxfun and calculating the distance as below( i am attaching a snippet of the code ):
for i=1:4754
...
6
votes
5
answers
16k
views
How to calculate Euclidean length of a matrix without loops?
It seems like the answer to this should be simple, but I am stumped. I have a matrix of Nx3 matrix where there 1st 2nd and 3rd columns are the X Y and Z coordinates of the nth item. I want to ...
6
votes
2
answers
1k
views
Matlab formula optimization: Radial Basis Function
z - matrix of doubles, size Nx2;
x - matrix of doubles, size Nx2;
sup = x(i, :);
phi(1, i) = {@(z) exp(-g * sum((z - sup(ones([size(z, 1) 1]),:)) .^ 2, 2))};
this is a Radial Basis Function (RBF) ...
3
votes
4
answers
881
views
Pairwise weighted distance vectorization
The following efficient and vectorized Matlab code computes the Weighted Euclidean Distance between 2 sets of points A and B using a weight vector WTS (1 weight for each dimension; same weights for ...
3
votes
3
answers
23k
views
How to calculate normalized euclidean distance on two vectors?
Let's say I have the following two vectors:
x = [(10-1).*rand(7,1) + 1; randi(10,1,1)];
y = [(10-1).*rand(7,1) + 1; randi(10,1,1)];
The first seven elements are continuous values in the range [1,10]....
3
votes
3
answers
12k
views
Euclidean Distance
I have two points
x1 = (a1,b1,c1,d1,e1); //5 dimensional point
x2 = (a2,b2,c2,d2,e2); //5 dimensional point
So is this right way to calculate the euclidean dist?
d = sqrt(sqr(a1-a2)+sqr(...
3
votes
4
answers
3k
views
Alternative to using squareform (Matlab)
At the moment i am using the pdist function in Matlab, to calculate the euclidian distances between various points in a three dimensional cartesian system. I'm doing this because i want to know which ...
3
votes
3
answers
3k
views
Calculating Euclidean distance of pairs of 3D points in matlab
I have an Nx3 array that contains N 3D points
a1 b1 c1
a2 b2 c2
....
aN bN cN
I want to calculate Euclidean distance in a NxN array that measures the Euclidean distance between each pair of 3D ...
3
votes
1
answer
7k
views
calculate Euclidean distance of two image in hsv color space in matlab
i use the code below to calculate the Euclidean distance for two rgb images:
Im1 = imread(filename1);
Im1 = rgb2gray(Im1);
hn1 = imhist(Im1)./numel(Im1);
Im2 = imread(filename2);
Im2 = rgb2gray(Im2);
...
3
votes
2
answers
7k
views
Euclidean distance between two set of 3D points
How can I find the nearest points of two set of 3D points(with different number,set1 includes 400 points and set2 includes 2000 points) and then find the Euclidean distance between set1 and result ...
2
votes
3
answers
199
views
How to vectorize finding the closest point out of a vector
BigList = rand(20, 3)
LittleList = rand(5, 3)
I'd like to find for each row in the big list the 'closest' row in the little list, as defined by the euclidean norm (i.e. sum of squared distances ...
2
votes
1
answer
2k
views
octave pdist (pairwise distance)
The octave documentation says pdist exists, but I cannot use it in my version installed on ubuntu 12.04.
Octave version:
GNU Octave, version 3.6.2
Copyright (C) 2012 John W. Eaton and others.
This ...
2
votes
2
answers
227
views
Compute the difference matrix between a matrix and another matrix in MATLAB
Given a matrix A in matlab with:
3 1
4 5
7 8
and another matrix B which could be referred to as some reference points (each row is reference point that is to be compared to each row of A),
1 ...
2
votes
1
answer
2k
views
Substitute function of bwdist in C++
I am implementing a code of Matlab in C++. In Matlab they have used bwdist to calculate the euclidean distance.
I am using the function distanceTransform to get the same result as in Matlab, but the ...
2
votes
2
answers
707
views
Remove Elements of matrix by eucledian distance
I have an mxn matrix with E nonzero elements. The coordinates of the nonzeros are already available in an Ex2 vector.
I'd like to check if the minimum Euclidean distance between every pair of ...
2
votes
1
answer
1k
views
relabeling pixels based on distance between object's centerline and boundary
I've a binary image containing an object as illustrated in the figure below. The centerline of the object is depicted in red. For each pixel belonging to the object, I would like to relabel it with a ...
2
votes
1
answer
895
views
Calculate distance matrix for 3D points
I have the lists xA, yA, zA and the lists xB, yB, zB in Matlab. The contain the the x,y and z coordinates of points of type A and type B. There may be different numbers of type A and type B points.
I ...
2
votes
3
answers
686
views
Subsequent time-series matching
I've been stuck with subsequent matching of time-series in MATLAB (I'm new to it).
I have two time-series: A (of length a) and B (of length b). Assume that a is much larger than b. The task is to ...
2
votes
4
answers
9k
views
How do I create a simliarity matrix in MATLAB?
I am working towards comparing multiple images. I have these image data as column vectors of a matrix called "images." I want to assess the similarity of images by first computing their Eucledian ...
2
votes
2
answers
82
views
How to compute the Euclidean distance between two complex matrix by vectorization?
X=[x_1,x_2,...,x_N] is a [S,N] complex matrix.
For example, S=3 and x_1=[1+2j,2+3j,3+4j]'.
D is the distance matrix of X, which means D(i,j) is the Euclidean distance between x_i and x_j.
my code:
D = ...
2
votes
1
answer
56
views
How to Divide Relative Distance into Three Equidistant Regions in MATLAB?
I have two distance maps. One refers to the distance from one point to the outside (starting at 0, ending at a high number reflecting distance from one point). The other is basically equal and ...
2
votes
1
answer
341
views
Calculate distance between every point of matrix with each other
I want to calculate the euclidean distance between every element of an n-channeled matrix to every other and then apply the function exp(-dist) to it. My matrix is MxN so the output must be (MxN)x(MxN)...
1
vote
2
answers
12k
views
SIFT feature matching through Euclidean distance
SIFT feature matching is done through a Euclidean-distance based nearest neighbor approach. Can some please explain this? Is there a calculation? If then can someone help me to calculate the Euclidean ...
1
vote
2
answers
194
views
MATLAB short way to find closest vector?
In my application, I need to find the "closest" (minimum Euclidean distance vector) to an input vector, among a set of vectors (i.e. a matrix)
Therefore every single time I have to do this :
...
1
vote
2
answers
138
views
Distances from a single point
I'm looking to generate a Euclidean distance matrix from one point [1,1]. This is what I have, however it doesn't work as intended:
a=rand(10,10);
a=sort(a); %sort example matrix it should be visible ...
1
vote
3
answers
256
views
Is there a way to calculate the following specified matrix by avoiding loops? in R or Matlab
I have an N-by-M matrix X, and I need to calculate an N-by-N matrix Y:
Y[i, j] = sum((X[i,] - X[j,]) ^ 2) 0 <= i,j <= N
For now, I have to use nested loops to do it with O(n2). I would like ...
1
vote
1
answer
643
views
How to generate random uniformly distributed vectors of euclidian length of one?
I am trying to randomly generate uniformly distributed vectors, which are of Euclidian length of 1. By uniformly distributed I mean that each entry (coordinate) of the vectors is uniformly distributed....
1
vote
2
answers
180
views
How to vectorize the code in MATLAB
I have some Cluster Centers and some Data Points. I want to calculate the distances as below (norm is for Euclidean distance):
costsTmp = zeros(NObjects,NClusters);
lambda = ...
1
vote
2
answers
3k
views
Finding maximum/minimum distance of two rows in a matrix using MATLAB
Say we have a matrix m x n where the number of rows of the matrix is very big. If we assume each row is a vector, then how could one find the maximum/minimum distance between vectors in this matrix?
1
vote
2
answers
3k
views
How to find distance matrix in matlab
I am using pdist2(x(i), y(j), 'euclidean') formula to find euclidean distance between x and y instead of the manual method
sqrt((x(i)-y(i))^2).
And to find co relation coefficient I am using ...
1
vote
1
answer
926
views
I just started to use Eigen Matrix algebra library and aim to create a similarity matrix of a dataset, suggestions?
I try to create a similarity matrix with eigen library on a dataset. I just read the csv file into eigen matrix but know as a matlab customer I am looking for something like bsxfun or something to ...
1
vote
2
answers
2k
views
MATLAB - efficient way of computing distances between points in a graph/network using the adjacency matrix and coordinates
I have the network representation in a 2D coordinate space. I have an adjacency matrix Adj(which is sparse) and a coordinate matrix with the x,y values of all the points/nodes/vertices in the graph ...
1
vote
3
answers
8k
views
Calculate distance, given a set of coordinates
my question is quite trivial, but I'm looking for the vectorized form of it.
My code is:
HubHt = 110; % Hub Height
GridWidth = 150; % Grid length along Y axis
GridHeight = 150; % Grid length ...
1
vote
1
answer
530
views
Max Euclidean distance between two columns of a matrix in Matlab / Octave
I need to calculate for a program the maximal euclidian distance of vectors that are put together in a matrix A in Octave.
What I have so far:
for i=1:n
for k=i:n+1
C=A(:,i)-A(:,k);
...
1
vote
2
answers
155
views
Create a one-sided distance map
I create with this code a black square of zeros with a white vertical line of ones at the middle and I want to create a distance map with respect to this line but only at the left side of the vertical ...
1
vote
1
answer
77
views
High performance computation of mean 2D-Euclidian-distance
Let's say I have a position matrix P with dimensions 10x2, where the first column contains x values and second column the corresponding y values. I want the mean of the lengths of the positions. The ...
1
vote
1
answer
1k
views
Distance transform `bwdist` output is completely black
Why is the bwdist and imhmin image completely black? When I check the the two matrices in the workspace, the values seem fine. You can run this code in Matlab to check it out. The expected result is a ...
1
vote
1
answer
5k
views
Calculate Euclidean distance between RGB vectors in a large matrix
I have this RGB matrix of a set of different pixels. (N pixels => n rows, RGB => 3 columns). I have to calculate the minimum RGB distance between any two pixels from this matrix. I tried the loop ...
1
vote
1
answer
1k
views
Efficient way to compute multiple euclidean distances Matlab
I am training my own self organizing map to cluster colorvalues. Now I want to make some sort of a U-matrix to show euclidean distances between the nodes and their direct neighbors. My problem now is, ...
1
vote
1
answer
226
views
Using norm Function In MATLAB
I have a matrix of data which is the coordinates of some points and coordinates of 5 clusters
data = [randi(100,100,1),randi(100,100,1)];
x_Clusters = [20 5 12 88 61];
y_Clusters = [10 50 14 41 10];
...
1
vote
1
answer
1k
views
Shortest distance between a specific object to other objects
Following these two posts that deals with finding the distance between objects in binary image, how can I only output/calculate only the shortest distance between a specific object to the rest (for ...
1
vote
1
answer
1k
views
Distance Calculations for Nearest Mean Classifer
Greetins,
How can I calculate how many distance calculations would need to be performed to classify the IRIS dataset using Nearest Mean Classifier.
I know that IRIS dataset has 4 features and every ...
1
vote
2
answers
2k
views
euclidean distance for each point in a point cloud
I want to compute the minimum eucidean distance between each point in one point cloud and all the other points in the second point cloud.
My point clouds are named pc1 and pc2.
Np is a matrix of ...
1
vote
1
answer
622
views
Distance between vector and a point
I have a point point=[x y] and a vector vec=[X Y], where X and Y are vectors containing x,y values for many point. I have calculated the euclidean distances of all the points in vec from point with ...
1
vote
1
answer
160
views
roc curve and speaker recognition
I am using Euclidean distance for speaker recognition. I want to plot the ROC curve using perfcurve in MATLAB. Since the scores are the resulting euclidean distances, am I doing right? Thanks
Labels=[...
1
vote
2
answers
2k
views
Euclidean and Mahalanobis classifiers always return same error for each classifier?
I have a simple matlab code to generate some random data and then to use a Euclidean and Mahalanobis classifier to classify the random data. The issue I am having is that the error results for each ...
1
vote
1
answer
226
views
Issue in generating noise and euclidean distance
(a) How do I generate noise such that the maximum levels of the added noise correspond with 3.9% to 50% of the average absolute deviation.
(b) How do I generate white Gaussian noise and uniform noise?...
1
vote
0
answers
617
views
Ellipse distance metric for DBSCAN clustering
I am using the DBSCAN algorithm to determine clusters in a data set obtained by an automotive radar. The paper "Grid-Based DBSCAN for Clustering Extended Objects in Radar Data" from Dominik Kellner, ...