Initializing Matrix for all possible sequences of numbers
조회 수: 1 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!