Identify the minimum number of rows in a matrix meeting a condition

Illustration
Jeremiah - 2020-07-20T13:05:12+00:00
Question: Identify the minimum number of rows in a matrix meeting a condition

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?

Expert Answer

Profile picture of Neeta Dsouza 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)));


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!