find distances between vectors in a cell array
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
so i have a 15x2 cell array where each row represents two sets of coordinate points i need to find the distances between:
[1,1] [4,4]
[1,1] [10,10]
[1,1] [1.50000000000000,1.50000000000000]
[1,1] [10.5000000000000,10.5000000000000]
[1.50000000000000,1] [4,4]
[1.50000000000000,1] [10,10]
[1.50000000000000,1] [1.50000000000000,1.50000000000000]
[1.50000000000000,1] [10.5000000000000,10.5000000000000]
[4,4] [10,10]
[4,4] [1.50000000000000,1.50000000000000]
[4,4] [10.5000000000000,10.5000000000000]
[10,10] [1.50000000000000,1.50000000000000]
[10,10] [10.5000000000000,10.5000000000000]
[1.50000000000000,1.50000000000000] [10.5000000000000,10.5000000000000]
pdist doesnt seem to work for me in this case bc the elements arent character arrays or strings. How would i go about this?
0 commentaires
Réponses (1)
Stephen23
le 12 Nov 2020
"pdist doesnt seem to work for me in this case bc the elements arent character arrays or strings."
According to the pdist documentation its first input must be numeric floating point, i.e. double or single.
Storing that data in a cell array is rather awkward, it would probably be simpler in one/two numeric arrays. However you can still use pdist on your pairs, with the help of cellfun:
C = {...
[1,1],[10,10]
[1,1],[1.5,1.5]
[1,1],[10.5,10.5]
[1.5,1],[4,4]
[1.5,1],[10,10]
[1.5,1],[1.5,1.5]
[1.5,1],[10.5,10.5]
[4,4],[10,10]
[4,4],[1.5,1.5]
[4,4],[10.5,10.5]
[10,10],[1.5,1.5]
[10,10],[10.5,10.5]
[1.5,1.5],[10.5,10.5]};
F = @(varargin)pdist(vertcat(varargin{:}));
D = cellfun(F,C(:,1),C(:,2))
0 commentaires
Voir également
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!