find distances between vectors in a cell array
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Stephen23
2020 年 11 月 12 日
"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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Statistics and Machine Learning Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!