フィルターのクリア

find distances between vectors in a cell array

1 回表示 (過去 30 日間)
That Guy
That Guy 2020 年 11 月 12 日
回答済み: Stephen23 2020 年 11 月 12 日
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?

回答 (1 件)

Stephen23
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))
D = 13×1
12.7279 0.7071 13.4350 3.9051 12.3794 0.5000 13.0863 8.4853 3.5355 9.1924

カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by