(Ask again)Show every combination of N-dim vector.
Ältere Kommentare anzeigen
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 Kommentare
Oleg Komarov
am 24 Mai 2012
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
am 24 Mai 2012
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
am 24 Mai 2012
@Sean you can double check your solution with unique(M, 'rows'), and it appears answers are repeated.
Sean de Wolski
am 24 Mai 2012
huh, your fullfact one is better anyway.
C Zeng
am 25 Mai 2012
Akzeptierte Antwort
Weitere Antworten (1)
Daniel Shub
am 24 Mai 2012
1 Stimme
Kategorien
Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!