How can I obtain all possible combinations of a given vector
1 次查看(过去 30 天)
显示 更早的评论
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 中查找有关 Electrical Block Libraries 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!