How to get all possible combinations of three independent data sets?
조회 수: 2 (최근 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!