MATLAB: Remove zeros from matrix and order by each row

matrix

Hi,
I have a matrix like this
A=[1 0 0;
1 0 0;
0 2 0;
0 2 0;
0 0 3;
0 0 3;
1 0 0;
1 0 0;
0 2 0;
0 2 0;
0 0 3;
0 0 3]
I want the output to look like this A_Final = [1;1;2;2;3;3;1;1;2;2;3;3].
I used nonzeros, but the output is like this, [1,1,1,1,2,2,2,2,3,3,3,3], not what I wanted, help!
Thanks!

Best Answer

A_Final = sum( A, 2 )