How to get all possible combinations of three independent data sets?
2 ビュー (過去 30 日間)
古いコメントを表示
Aris van Houten
2021 年 4 月 14 日
コメント済み: Aris van Houten
2021 年 4 月 14 日
Hello All,
I have the following problem:
I have three independent data sets of x- and y- coordinates, let them be as follows for now:
Data set 1:
A = [A_x A_y];
B = [B_x B_y];
C = [C_x C_y];
Data set 2:
D= [D_x D_y];
E = [E_x E_y];
F = [F_x F_y];
G = [G_x G_y];
Data set 3:
H = [H_x H_y];
I = [I_x I_y];
J = [J_x J_y];
I want to generate all possible combinations with a length of 3, but there can only be one for each data set:
For example:
ADJ is ok (consits of three points in three different data sets)
BEG is not ok (because E and G are in data set 2)
P.S. The real data sets consists of 30+ coordinates
Thanks you very much in advance!
0 件のコメント
採用された回答
Walter Roberson
2021 年 4 月 14 日
A = [A_x A_y];
B = [B_x B_y];
C = [C_x C_y];
ABC = [A;B;C];
D= [D_x D_y];
E = [E_x E_y];
F = [F_x F_y];
DEF = [D;E;F];
G = [G_x G_y];
H = [H_x H_y];
I = [I_x I_y];
J = [J_x J_y];
GHIJ = [G;H;I;J];
[g1, g2, g3] = ndgrid(1:size(ABC,1), 1:size(DEF,1), 1:size(GHIJ,1));
g123 = [g1(:),g2(:), g3(:)];
all_combs = [ABC(g123(:,1),:),DEF(g123(:,2),:),GHIJ(g123(:,3),:)];
The g* variables are indices. Generate all combinations of indices using ndgrid(), and then use the indices to index into the respective dataset.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!