필터 지우기
필터 지우기

How to find the minimum set of columns in a matrix to ensure every row has at least one nonzero value

조회 수: 2 (최근 30일)
Hi. I'm hoping somebody knows of an elegant way to do this. I have an array of logical values MxN. I'm trying to find the minimum set of columns of that matrix such that every row has at least one true value.
A = rand(100,100)>0.5
The best I've got so far is to choose one column to start with, and then iteratively go through and find the column which has the highest impact on my end goal and include that. But I know that this doesn't ensure the best solution.

답변 (1개)

Star Strider
Star Strider 2016년 5월 4일
If you’re looking column-wise to see what columns have one true value in every row (the way I interpret your question), then sum the matrix and look for column sums that equal ‘M’. All rows in that column would have to be true.
  댓글 수: 2
Dan K
Dan K 2016년 5월 4일
Thanks,
Unfortunately that's not what I'm trying to achieve. I can easily test to see if there exists a column where every row is true. What I'm trying to do is find the minimum collection of columns such that:
all(sum(A(:,[column_indices]),2) > 0) is true
Star Strider
Star Strider 2016년 5월 4일
My pleasure.
I’m obviously missing something. A small example would help.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by