MATLAB: How to eliminate column of the matrix

column eliminate

Hello everyone!
I have generated some matrix of size say mxn. I want to eliminate the columns which have all values equal to "0".
For example:
A=[ 1 2 3 ... 2 0
2 3 5 ... 3 0
3 5 6 ... 3 0]
Desired output
A=[1 2 3 ... 2
2 3 5 ... 3
3 5 6 ... 3]

Best Answer

A(:,all(A==0)) = []