I am trying to calculate the Euclidean distance of pairs of points $(x_i,y_i)$ with $x$ and $y$ given as separate lists.
sqdiff = {};
For[i = 1, i < Length[x] - 1, i++,
{
For[j = i + 1, j < Length[x], j++,
{
AppendTo[sqdiff, (x[[i]] - x[[j]])^2 + (y[[i]] - y[[j]])^2];
}
]
}
]
Even for 800 points, this loops takes orders of magnitudes longer than an identical loop written in MATLAB. Are there any improvements I can make? Thanks.
DistanceMatrix
, vectorize it, etc. $\endgroup$For
/for
and the to the successiveAppendTo
(cat
in MATLAB). $\endgroup$