(Ask again)Show every combination of N-dim vector.
이전 댓글 표시
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
Oleg Komarov
2012년 5월 24일
Please familiarize with the formatting capabilites on: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
Especially with the code section.
Sean de Wolski
2012년 5월 24일
How does this not work?
If I use N = 4; I get an 81x4 matrix of all possibilities. 3^N is 81.
etc. for all N.
Please elaborate on what doesn't work and please post this as a comment in your other question.
Daniel Shub
2012년 5월 24일
@Sean you can double check your solution with unique(M, 'rows'), and it appears answers are repeated.
Sean de Wolski
2012년 5월 24일
huh, your fullfact one is better anyway.
C Zeng
2012년 5월 25일
채택된 답변
추가 답변 (1개)
Daniel Shub
2012년 5월 24일
1 개 추천
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!