(Ask again)Show every combination of N-dim vector.
Afficher commentaires plus anciens
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 commentaires
Oleg Komarov
le 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
le 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
le 24 Mai 2012
@Sean you can double check your solution with unique(M, 'rows'), and it appears answers are repeated.
Sean de Wolski
le 24 Mai 2012
huh, your fullfact one is better anyway.
C Zeng
le 25 Mai 2012
Réponse acceptée
Plus de réponses (1)
Daniel Shub
le 24 Mai 2012
1 vote
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!