Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

How to get pdist() values of all the rows of a matrix with respect to a row of the same matrix?

1 vue (au cours des 30 derniers jours)
ejt
ejt le 13 Juin 2018
Clôturé : ejt le 18 Juin 2018
Say, for example, I have a matrix x =[0 0; 1 0; 0 2; 3 0]. If I use pdist(x), Matlab will output all the Euclidean distance between every row of the matrix. But I want the distance with respect to only the first row. Output, something like [0; 1; 2; 3]. I am aware that I could select the first few entries of the result from pdist(x) to get the matrix as desired. But, as the size of matrix x increases there will be a lot of unnecessary computations happening, which I would like to avoid. I realize that I could have probably written a function instead of asking here. Let me know if there is a workaround to this problem, which will be beneficial in the future. Thanks.

Réponses (1)

Nithin Banka
Nithin Banka le 18 Juin 2018
diffX = X - X(1, :);
yourReqOutput = sqrt(sum(diffX.^2, 2));%first row will be 0 as it is distance from itself.

Cette question est clôturée.

Tags

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by