Compute distances between an element and all other elements of a matrix

조회 수: 5 (최근 30일)
Hello,
Please help me with the following:
I have a matrix M 150x4.
Ι need to calculate the distances (separately, the Euclidean and Cityblock) between the 1st element M(1,1) and all the others of M.
Also, I need to plot these distances.
Thank you very much.
Best,
Pavlos
  댓글 수: 1
Rik
Rik 2018년 4월 6일
What have you tried already? It is more useful for you to have your code improved than someone else doing your homework.
What defines the distance between element? And how do you want to plot the distance? Just as a 3D point cloud?

댓글을 달려면 로그인하십시오.

채택된 답변

David Fletcher
David Fletcher 2018년 4월 6일
If you have the statistics toolbox you can use pdist2
m=[1 1 1 1;2 2 2 2;3 3 3 3;4 4 4 4;5 5 5 5]
dist1=pdist2(m(1,:),m,'euclidean')
dist2=pdist2(m(1,:),m,'cityblock')
%plot index vs distance
plot(1:length(c),[dist1;dist2])

추가 답변 (0개)

카테고리

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