How do I create a series of permutation matrices

Hi all,
I'm new, and my maths isn't great. Was wondering if anyone could help me..
I want to create a series of matrices (zeros(3,3)) that show all possible combinations of making 1-6 of the 9 values a 1.
Mathematically, this should produce; 9nCr1 = 9 + 9nCr2 = 36 + 9nCr3 = 84 + 9nCr4 = 126 + 9nCr5 = 126 + 9nCr6 = 84 = 465 separate matrices
Does anyone know how to do that without manually specifying all of them?

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 11월 8일
편집: Andrei Bobrov 2012년 11월 8일

1 개 추천

a = dec2bin(0:511,9) - '0';
n = sum(a,2);
out = reshape(a(n <= 6 & n >= 1,:).',3,3,[]);
ADD
a = dec2bin(0:511,9) - '0';
n = sum(a,2);
out = reshape(a(n <= 6 & n >= 1 & all(a(:,[1:4:9])==0,2),:).',3,3,[]);

댓글 수: 5

Josh
Josh 2012년 11월 8일
Andrei Bobrov, you are a hero!
Sorry for a follow up - but now I want to remove any matrices where (1,1,:) + (2,2,:) + (3,3,:) > 0.
I have tried the following but it doesn't work;
a = dec2bin(0:511,9) - '0';
n = sum(a,2);
out = reshape(a(n <= 6 & n >= 1,:).',3,3,[]);
for j = 1:length(out)
if (out(1,1,j) + out(2,2,j) + out(3,3,j)) > 0
out(:,:,j) = [];
end
end
Josh
+1 I would have never understood what Josh meant.
see ADD
Josh
Josh 2012년 11월 8일
Thanks!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2012년 11월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by