MATLAB: Cutting rows and columns from a matrix

matrix manipulation

If A = [0,0,0,0;0,0,0,0;0,0,1,1;0,0,1,1], how can i cut out the null comumns and rows to acheive B = [1,1;1,1]

Best Answer

See ANY (or ALL). You need a two step approach:
A = [1 0 1 0 ; 1 0 1 0 ; 0 0 0 0]
B = A(any(A,2),:) ; % remove null rows
B = B(:,any(A,1)) % remove null columns