Effacer les filtres
Effacer les filtres

Initializing Matrix for all possible sequences of numbers

1 vue (au cours des 30 derniers jours)
Will
Will le 17 Oct 2011
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.

Réponse acceptée

Daniel Shub
Daniel Shub le 17 Oct 2011
doc perms
perms(1:3)

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by