Please assume that I have a matrix as follows: A = [0 1 0 0 1 1 0 0 0 0 1 0 0 0 0 1 1 0 1 1] I would like to identify and selcet the minimum number of rows that have value of one in all columns (altoghether). For example, rows 2 and 5 are the best choice for matrix A. Do you have any suggestion?
Neeta Dsouza answered .
2025-11-20
This solution uses the Optimization Toolbox, although I am still only half certain what row-selection rule you are looking for
[m,n]=size(A);
irp=1:m;
rp=randperm(m); %row permutation
irp(rp)=irp; %inverse permutation
Ap=A(rp,:);
x=optimvar('x',[1,m],'LowerBound',0,'UpperBound',1,'Type','integer');
prob=optimproblem('Objective',sum(x));
prob.Constraints=(x*Ap>=ones(1,n));
sol=solve(prob);
selection=find(round(sol.x(irp)));