A = [ -1 1 0 0 0 0
0 -1 2 1 3 0
0 3 -2 1 0 0
0 0 1 0 4 0
1 0 0 2 -1 0
0 -1 0 0 0 3
2 0 0 0 0 1];
j=1;
[m,n]=size(A);
n0=nnz(A(j,:));
if n0==1
rows=A(j,:),
else
C=double( logical( A(:, ~A(j,:) ) ));
[~,nc]=size(C);
x=optimvar('x',[m,1], 'Low',0,'Up',1,'Type','integer'); x.LowerBound(j)=1;
y=optimvar('y',[1,nc], 'Low',0,'Up',1,'Type','integer');
prob=optimproblem('Objective',sum(x));
prob.Constraints.xineq=sum(x)>=n0;
prob.Constraints.yupper=x.'*C>=y;
prob.Constraints.ylower=x.'*C<=m*y;
prob.Constraints.nz=sum(x)-sum(y)==n-nc;
[sol,numrows]=solve(prob);
rows=A(round(sol.x)>0,:)
end
4 Comments
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/511969-how-to-find-a-minimal-number-of-rows-in-a-sparse-matrix-to-form-a-square-sub-matrix-for-a-given-row#comment_812799
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/511969-how-to-find-a-minimal-number-of-rows-in-a-sparse-matrix-to-form-a-square-sub-matrix-for-a-given-row#comment_812799
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/511969-how-to-find-a-minimal-number-of-rows-in-a-sparse-matrix-to-form-a-square-sub-matrix-for-a-given-row#comment_812808
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/511969-how-to-find-a-minimal-number-of-rows-in-a-sparse-matrix-to-form-a-square-sub-matrix-for-a-given-row#comment_812808
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/511969-how-to-find-a-minimal-number-of-rows-in-a-sparse-matrix-to-form-a-square-sub-matrix-for-a-given-row#comment_812814
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/511969-how-to-find-a-minimal-number-of-rows-in-a-sparse-matrix-to-form-a-square-sub-matrix-for-a-given-row#comment_812814
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/511969-how-to-find-a-minimal-number-of-rows-in-a-sparse-matrix-to-form-a-square-sub-matrix-for-a-given-row#comment_812816
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/511969-how-to-find-a-minimal-number-of-rows-in-a-sparse-matrix-to-form-a-square-sub-matrix-for-a-given-row#comment_812816
Sign in to comment.