(Ask again)Show every combination of N-dim vector.
Mostrar comentarios más antiguos
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 comentarios
Oleg Komarov
el 24 de Mayo de 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
el 24 de Mayo de 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
el 24 de Mayo de 2012
@Sean you can double check your solution with unique(M, 'rows'), and it appears answers are repeated.
Sean de Wolski
el 24 de Mayo de 2012
huh, your fullfact one is better anyway.
C Zeng
el 25 de Mayo de 2012
Respuesta aceptada
Más respuestas (1)
Daniel Shub
el 24 de Mayo de 2012
1 voto
Categorías
Más información sobre MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!