Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to calculate the corresponding distance between each data set in a high-dimensional space?

Subject: How to calculate the corresponding distance between each data set in a high-dimensional space?

From: Hero Lee

Date: 22 Feb, 2009 00:34:02

Message: 1 of 2

Hi, Dear Sir or Madam,

   There are a number of data sets (x, y, z) locating in a 3-Dimensional sapce, and I would like to generate a table (or a matrix) displaying the corresponding value of Eulidean Distance between each data set in the 3-Dimensional sapce. For example,
A(0,0,0), B(1,0,0), C(1,2,0)....N(Xn,Yn,Zn) are locating in a 3-Dimensional sapce, so the table (or a matrix) can be represented as follows:

      A B C ... N
A 0 1 2.23 ... Sqrt(A^2-N^2)
B 1 0 2 ... Sqrt(B^2-N^2)
C 2.23 2 0 ... Sqrt(C^2-N^2)
. . . . ...

N . . . ... 0

Also, I would like to calculate the average value of the total value in the table.
Hence, please kindly give me a sample code. Really thank you so much.

Cheers,

Subject: How to calculate the corresponding distance between each data set in a high-dimensional space?

From: Roger Stafford

Date: 22 Feb, 2009 01:19:01

Message: 2 of 2

"Hero Lee" <hero@mathworks.com> wrote in message <gnq6hq$ald$1@fred.mathworks.com>...
> Hi, Dear Sir or Madam,
>
> There are a number of data sets (x, y, z) locating in a 3-Dimensional sapce, and I would like to generate a table (or a matrix) displaying the corresponding value of Eulidean Distance between each data set in the 3-Dimensional sapce. For example,
> A(0,0,0), B(1,0,0), C(1,2,0)....N(Xn,Yn,Zn) are locating in a 3-Dimensional sapce, so the table (or a matrix) can be represented as follows:
>
> A B C ... N
> A 0 1 2.23 ... Sqrt(A^2-N^2)
> B 1 0 2 ... Sqrt(B^2-N^2)
> C 2.23 2 0 ... Sqrt(C^2-N^2)
> . . . . ...
>
> N . . . ... 0
>
> Also, I would like to calculate the average value of the total value in the table.
> Hence, please kindly give me a sample code. Really thank you so much.
>
> Cheers,

  For simplicity let's suppose the points are located in an N x 3 array called M. Call the H x N array of distances D.

 [I,J] = ndgrid(1:N,1:N);
 D = reshape(sqrt(sum((M(I,:)-M(J,:)).^2,2)),N,N);

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us