MATLAB: How to find columns with all zeros in the matrix

columnsmatrixnonzero entrieszero

I've got a large matrix A and would like to find out if any of the columns contain only zeros. I've found a solution for finding all the rows with only zeros but I'm not sure how to make it all columns.
Also, would there be a way to find out which columns have exactly 4 or 3 or 2 or X nonzero entries?

Best Answer

cols_with_all_zeros = find(all(A==0)); % all zeros
cols_with_3_nonzeros = find(sum(A~=0)==3); % exactly 3 non-zeros