Find unique permutations of a matrix
조회 수: 7 (최근 30일)
이전 댓글 표시
I want to construct all possible matrices with N elements. Example: if N=6, then I want a 1x6, 2x3 3x2 and 6x1 matrix. These matrices should all be unique. So if we consider a 2x3 matrix, the options would be: [1 2 3; 4 5 6], [1 2 4; 3 5 6], [1 2 5; 3 4 6], [1 2 6; 3 4 5], [1 3 4; 2 5 6], [1 3 5; 2 4 6], etc. For this matrix there will be 10 unique combinations. A similar expression for a 3x2 matrix can be obtained: [1 2; 3 4; 5 6], [1 2; 3 5; 4 6], [1 2; 3 6; 4 5], [1 3; 2 4; 5 6], etc. For this matrix there will be 15 unique combinations. The 1x6 and 6x1 matrices only contain 1 unique combination each. Note that the order of rows and the order within each row does not matter and each number can only be used once! So far, I did this manually for N=1:7. For a larger number of N, the number of combinations will explode. For N=12, there will be 32034 combinations possible...
I already did several attempts to obtain all possible matrices and searched for people who tackled similar problems . However, these options do not give the desired results. Can someone please help me? Thank you in advance!
댓글 수: 1
Bruno Luong
2018년 11월 22일
편집: Bruno Luong
2018년 11월 22일
"For a larger number of N, the number of combinations will explode. For N=12, there will be 32034 combinations possible..."
At least you realize you are engaging in the bad way solving of whatever the problem you want to solve.
I count 2874009600 combinations possible.
답변 (1개)
Bruno Luong
2018년 11월 22일
N = 6;
p = factor(N);
q = length(p);
b = dec2bin(0:2^q-1,q)-'0';
m = unique(prod(b.*p+(1-b),2));
n = N./m;
C = num2cell(perms(1:N),2);
reshapefun = @(m,n) cellfun(@(A) reshape(A,[m n]), C, 'unif', 0);
C = arrayfun(@(m,n) reshapefun(m,n), m, n, 'unif', 0);
C = cat(1,C{:})
댓글 수: 5
Bruno Luong
2018년 11월 22일
편집: Bruno Luong
2018년 11월 22일
How voltage/current criteria translates to the array values? sum(a,2) is the same? Or something more complicated such as Kirshoff's circuit law?
There are other numerical technique to optimize the arrangement on whatever criteria you want to optimize. IMHO going bruteforce is not a wise way to go.
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!