フィルターのクリア

(Ask again)Show every combination of N-dim vector.

2 ビュー (過去 30 日間)
C Zeng
C Zeng 2012 年 5 月 24 日
Hello, I asked it the day before yesterday but the code some expert told does not work well.
He wrote:
[C{1:N}]=ndgrid(0:2);
M=reshape(vertcat(C{:}),[],N);
However, it does show 3^N rows, but not every combination of N-dim vector of {0,1,2}. Is there another way to show all 3^N combinations and put it in a matrix?
Thank you so much!
  5 件のコメント
Sean de Wolski
Sean de Wolski 2012 年 5 月 24 日
huh, your fullfact one is better anyway.
C Zeng
C Zeng 2012 年 5 月 25 日
Yes, Sean, your code gives 3^N rows, but they have repeated one. Also I do not understand what does it mean? It seems that it is going to construct a grid in graphics, right? But I want all factorial combinations.

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

採用された回答

Daniel Shub
Daniel Shub 2012 年 5 月 24 日
I will repeat the answer I gave to your original question
x = fullfact([3,3,3])-1
EDIT
For a general N
N = 3;
x = fullfact(repmat(3, N, 1))-1
  9 件のコメント
Daniel Shub
Daniel Shub 2012 年 5 月 25 日
See my edit.
C Zeng
C Zeng 2012 年 5 月 25 日
Oh, yes, or using combinator.m file:
combinator(3,N)-1
Thank you so much!

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

その他の回答 (1 件)

Daniel Shub
Daniel Shub 2012 年 5 月 24 日

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by