MATLAB: How to return all columns in a logical array that have a non-zero value

logicalarrayMATLAB

I have a logical array of 100 columns each with 7 rows consisting of zeros and ones. Most of the columns add up to zero but I was wondering if there was a function to return the row numbers that have a non-zero value? Thank you

Best Answer

I think you want to get the column numbers instead of row numbers, as you mentioned in the question. Try this
M; % 7x100 matrix
idx = find(any(M))
idx are the column numbers with atleast one non-zero value.