nz = logical(A);
B = A(sum(nz,2) >= size(A,2)/2, sum(nz) >= size(A,1)/2);
You will notice this gives a 3 x 2 array, not a 2 x 2 array. The row 0 1 2 0 does not have more 0 than values, so it needs to be kept.
If you change the rules to say that you are not to keep something unless the number of values exceeds 1/2 of the possible, then you need to eliminate the third column of A, [0; 2; 8; 2; 0; 0] because in that case 3 entries out of 6 are populated and 3 does not exceed (6/2)
Best Answer