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 matrix 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]));
or,equivalently,
D = pdist2([Y Z],[Y Z]).
But, since D
is a symmetric matrix, I'd like to generate only the N(N + 1)/2
independent entries and store them into a row-ordered vector Dd
.
So the question is: how to generate a row-ordered array Dd
whose entries are defined by the lower triangular terms of matrix D
? I'd, furthermore, like storing the entries in a column-major order.
I hope the explanation is clear enough.
[1,N*(N+1)/2]
array, so onlyN*(N+1)/2
entries. – fpe