How can I obtain all possible combinations of a given vector
조회 수: 2 (최근 30일)
이전 댓글 표시
subhashree priyadarshini
2020년 10월 2일
댓글: subhashree priyadarshini
2020년 10월 2일
I have a vector A=[1 1 1 0 0 1 1]. I want all the possible combinations as following....
A=[1 1 1 0 0 0 0; 1 1 0 0 0 1 0; 1 1 0 0 0 0 1; 0 1 1 0 0 1 0; 0 1 1 0 0 0 1; 0 1 0 0 0 1 1]
댓글 수: 4
Stephen23
2020년 10월 2일
편집: Stephen23
2020년 10월 2일
Why is
0 1 0 0 0 1 1
included, but
0 0 1 0 0 1 1
1 0 0 0 0 1 1
are excluded?
Although you write in your question that you want "all combinations", it seems that you actually want a subset of the combinations, but so far the rules to derive that subset are not clear to me.
채택된 답변
Stephen23
2020년 10월 2일
Brute force, not particularly efficient:
>> A = [1,1,1,0,0,1,1];
>> P = unique(bsxfun(@and,A,unique(perms(A),'rows')),'rows');
>> P(sum(P,2)~=3,:)=[]
P =
0 0 1 0 0 1 1
0 1 0 0 0 1 1
0 1 1 0 0 0 1
0 1 1 0 0 1 0
1 0 0 0 0 1 1
1 0 1 0 0 0 1
1 0 1 0 0 1 0
1 1 0 0 0 0 1
1 1 0 0 0 1 0
1 1 1 0 0 0 0
댓글 수: 3
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!