How to find the minimum set of columns in a matrix to ensure every row has at least one nonzero value
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuestas (1)
Star Strider
el 4 de Mayo de 2016
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 comentarios
Star Strider
el 4 de Mayo de 2016
My pleasure.
I’m obviously missing something. A small example would help.
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!