Non-repeating selection from sets
조회 수: 2 (최근 30일)
이전 댓글 표시
A is 1 by a matrix, B 1 by b, and C 1 by c. D is supposed to be the set of all non-repeating selection of respectively A, B, and C columns. What would be the most economical code of triples extraction? Thanks.
댓글 수: 0
채택된 답변
Dyuman Joshi
2023년 12월 27일
편집: Dyuman Joshi
2023년 12월 28일
%Random data
A = 1:3;
B = 1:4;
C = 1:5;
D = {A, B, C}
n = numel(D);
%Preallocate
out = cell(1, n);
%Reverse order to get the lexicographical order when concatenating
[out{end:-1:1}] = ndgrid(D{end:-1:1});
%Concatenate and reshape the data corresponding to number of vectors
out = reshape(cat(n,out{:}),[],n);
disp(out)
댓글 수: 4
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!