フィルターのクリア

Initializing Matrix for all possible sequences of numbers

1 回表示 (過去 30 日間)
Will
Will 2011 年 10 月 17 日
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.

採用された回答

Daniel Shub
Daniel Shub 2011 年 10 月 17 日
doc perms
perms(1:3)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by