필터 지우기
필터 지우기

Distance between elements of matrix

조회 수: 3 (최근 30일)
Kartik
Kartik 2013년 9월 14일
I have a single line matrix in Matlab
U= -25.2465 -5.1193 44.1124 -18.1332 9.2715 43.7203 -48.6050.
What i want to find is the distance between consecutive elements..
For ex:- first selecting the first point -25.2465 and finding the distance with all other points..In the same way simultaneously selecting -5.1193,44.1124..and so on.
The output i intend to get is a distance matrix
0 (-5.11+25.24) ... ... ... ... ...
(25.324-5.1) 0
(25.24+44.11) (-5.11+44.93) ... ... ... ... ...
(25.24-18.13) ...
(25.24+9.71) ...
...
How should i write this code

채택된 답변

Andrei Bobrov
Andrei Bobrov 2013년 9월 14일
out = abs(bsxfun(@minus,U,U'));
or use function dist from Neural Network Toolbox
out = dist(U);

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 14일
n=numel(A)
B=-diff(A(fullfact([n n]))')'

카테고리

Help CenterFile Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by