Borrar filtros
Borrar filtros

Find euclidean distance of a m X 2 matrix

2 visualizaciones (últimos 30 días)
Subhrajit Debnath
Subhrajit Debnath el 26 de Mayo de 2012
Suppose I have a =( 1 ,2; 3, 4;5,6); 3 X 2 matrix
x =( 1,10); 2 X 1 matrix
bsx_out = bsxfun(@minus,a,x); % i have done row wise subtraction.
I want to find the euclidean distance as a 3 X 1 column vector
so for first row it will be sqrt( (1-1)^2 + (2-10)^2)

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 26 de Mayo de 2012
a =[ 1 ,2; 3, 4;5,6]
x =[1,10]'
out = sqrt(sum(bsxfun(@minus,a,x.').^2,2))

Más respuestas (1)

Oleg Komarov
Oleg Komarov el 26 de Mayo de 2012
An alternative:
out = hypot(a(:,1)-x(1),a(:,2)-x(2))

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by