Borrar filtros
Borrar filtros

Initializing Matrix for all possible sequences of numbers

1 visualización (últimos 30 días)
Say n=3, I want to initialize this vector...
[1 2 3; 1 3 2; 2 1 3; 2 3 1; 3 1 2; 3 2 1]
That is, all possible sequences for 1, 2 and 3.
n = 3
np = factorial(n); % Number of possible combinations
m = zeros(np,n); % Allocate matrix
for i = 1:np
for j = 1:szp
m(i,j) = 1
end
end
So, this is how far I am now. This writes 1 into m(1,1) then m(1,2)......m(6,3).
I can't think of a way using a loop to change the matrix to how I want to.
Any help is much appreciated.

Respuesta aceptada

Daniel Shub
Daniel Shub el 17 de Oct. de 2011
doc perms
perms(1:3)

Más respuestas (0)

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