how many ways to arrange numbers from 1-3?

1 visualización (últimos 30 días)
Ali Noori
Ali Noori el 13 de Oct. de 2015
Respondida: Jos (10584) el 16 de Oct. de 2015
how many ways to arrange numbers from 1-3?
I want answer like this
[1,1,1]
[1,1,2]
[1,1,3]
[1,2,1]
[1,2,2]
[1,2,3]
[1,3,1]
[1,3,2]
[1,3,3]
[2,1,1]
[2,1,2]
[2,1,3]
[2,2,1]
[2,2,2]
[2,2,3]
[2,3,1]
[2,3,2]
[2,3,3]
[3,1,1]
[3,1,2]
[3,1,3]
[3,2,1]
[3,2,2]
[3,2,3]
[3,3,1]
[3,3,2]
[3,3,3]
Can you please put these values in one matrix?

Respuesta aceptada

Walter Roberson
Walter Roberson el 13 de Oct. de 2015
[A,P,Z] = ndgrid(1:3);
[Z(:), P(:), A(:)]
  2 comentarios
Ali Noori
Ali Noori el 16 de Oct. de 2015
thank u can u send me code to arrange number from 1-5
Walter Roberson
Walter Roberson el 16 de Oct. de 2015
Editada: Walter Roberson el 16 de Oct. de 2015
N = 5;
[A{1,1:N}] = ndgrid(1:N);
Result = cell2mat( cellfun(@(V) V(:), fliplr(A), 'Uniform', 0) );

Iniciar sesión para comentar.

Más respuestas (1)

Jos (10584)
Jos (10584) el 16 de Oct. de 2015
You might also be interested in PERMN: http://www.mathworks.com/matlabcentral/fileexchange/7147

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by