how to generate a matrix with all possible combinations in an efficient way
1 回表示 (過去 30 日間)
古いコメントを表示
I have n=1:4 and m=3, and I want to generate a matrix S whose rows are all the possible combinations.. i.e., S has 4^3 rows and 3columns. What is the mist efficient way to do this as I want to extend matrix to be of 50^10 rows and 10 columns (very large)
3 件のコメント
Guillaume
2019 年 8 月 30 日
very large is a massive understatement, as Bruno says. Looking a this wikipedia entry, you might be able to store your matrix if you manage to convice google to lend you all of their data centres. Good luck!
回答 (1 件)
Guillaume
2019 年 8 月 30 日
%n: a vector of numbers
%m: a scalar integer
allcombs = cell(1, m);
[allcombs{:}] = ndgrid(n);
allcombs = reshape(cat(m+1, allcombs{:}), [], m);
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!