필터 지우기
필터 지우기

Find euclidean distance of a m X 2 matrix

조회 수: 2 (최근 30일)
Subhrajit Debnath
Subhrajit Debnath 2012년 5월 26일
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)

채택된 답변

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

추가 답변 (1개)

Oleg Komarov
Oleg Komarov 2012년 5월 26일
An alternative:
out = hypot(a(:,1)-x(1),a(:,2)-x(2))

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by