MATLAB: How to generate binary matrix with all combination having equal probability of 1 and 0

communicationmatrix

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

Best Answer

You mean like this (I hope this wasn't your homework):
for k = 1 : 70
indexes = randperm(8);
array = zeros(1,8);
array(indexes(1:4)) = 1
end