Non-repeating selection from sets
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Amir Mahmoudi
il 27 Dic 2023
Commentato: Amir Mahmoudi
il 28 Dic 2023
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 Commenti
Risposta accettata
Dyuman Joshi
il 27 Dic 2023
Modificato: Dyuman Joshi
il 28 Dic 2023
%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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!