フィルターのクリア

Creating matrix of unique combinations of variables

4 ビュー (過去 30 日間)
Brian
Brian 2015 年 10 月 18 日
コメント済み: Brian 2015 年 10 月 19 日
I need to create a matrix that lists out each combinations of variables in each row.
Assume that I have 5 variables a1, a2, a3, a4, a5 that all have 10 possible values of 0.1:0.1:1, what is an elegant way to list out the 10^5 rows of combinations?
Thank you so much!

採用された回答

Walter Roberson
Walter Roberson 2015 年 10 月 19 日
nvals = 5;
[a{1:nvals}] = ndgrid(0.1:0.1:1);
Result = cell2mat(cellfun(@(C) C(:), a, 'Uniform', 0));
  1 件のコメント
Brian
Brian 2015 年 10 月 19 日
thanks! this worked like a charm!

サインインしてコメントする。

その他の回答 (1 件)

Martin Schätz
Martin Schätz 2015 年 10 月 18 日
Hi, it would be nice to have some code to work with included. But this is actually thing you would easily solve with MatLab help. Look at perms function. Input is your data and output is array of all possible combinations.

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by