How to get all possible combinations of three independent data sets?
3 次查看(过去 30 天)
显示 更早的评论
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!