Effacer les filtres
Effacer les filtres

Faster way to calculate the euclidean distance of a matrix than pdist and squareform?

2 vues (au cours des 30 derniers jours)
design=[0.625 0.875;0.25 0.75;0.375 0.125;0.875 0.375;0.125 0.625;
0 0;0.5 0.5;0.75 0.25;0.6875 0.0625;0.0625 0.8125;0.1875 0.6875;0.3125 0.3125;
0.4375 0.9375;0.5625 0.5625;0.9375 0.1875;0.8125 0.4375];
v=16;
tic
d(:,:)=squareform(pdist(design(1:v,:))).^2;
toc
This code needs about 0.009 seconds to run. I need something faster, because this calculation is in a for loop. Thank you in advance.

Réponse acceptée

Walter Roberson
Walter Roberson le 21 Juil 2016
You can use bsxfun of @minus to do the subtractions, then .^2 to square the components, sum() along the appropriate dimension, and .^(1/2) the result. This should be marginally faster than calling pdist, but probably not much faster.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by