Drexel dragonThe Math ForumDonate to the Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Calculate distance matrix
Replies: 3   Last Post: Jun 4, 2013 10:10 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Francesco Perrone

Posts: 39
Registered: 5/2/12
Calculate distance matrix
Posted: Jun 4, 2013 7:51 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi everybody,

I hope you will have the right answer to this question, which is rather challanging.

I have two uni-dimensional vectors Y and Z, which hold the coordinates of N grid points located on a square grid. So

Ny points along Y
Nz points along Z
N = Ny*Nz
Y = Y[N]; (Y holds N entries)
Z = Z[N]; (Z holds N entries)

Now, the goal would be generating the distance matriy D, which holds N*N entries: so each row of matrix D is defined as the distance between the i-th point on the grid and the remnant (N - i) points.

Generally, to compute the whole matrix I would call

D = squareform(pdist([Y Z]));
D = pdist2([Y Z],[Y Z]).

But, since D is a square matrix, I'd like to generate only the N(N + 1)/2 independent entries and store them into a uni-dimensional vector Dd.

So the question is: how to generate a uni-dimensional array Dd whose entries are the defined by the lower traingular terms of matrix D? I'd, furthermore, like storing the entries in a column-major order.

I hope the explanation is clear enough.

Thanks in advance,

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2016. All Rights Reserved.