how to generate binary matrix with all combination having equal probability of 1 and 0 ?
Show older comments
I want to generate binary matrix let say 8X1, In which four 0s and four 1s. so total number of such type of possible matrix would be 70, (see, 8Choose4 ).I want each of these one by one(may be with loop). Please help
Accepted Answer
More Answers (2)
Azzi Abdelmalek
on 15 Sep 2013
This is not the more efficient way
a=[1 1 1 1 0 0 0 0];
b=unique(perms(a),'rows');
out=b(sum(b,2)==4,:)
Andrei Bobrov
on 15 Sep 2013
Edited: Andrei Bobrov
on 16 Sep 2013
n = 8;
m = 4;
i0 = nchoosek(1:n,m);
s = size(i0,1);
out = zeros(s,n);
ii = bsxfun(@plus,(i0 - 1)*s,(1:s)');
out(ii) = 1;
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!