Cutting rows and columns from a matrix

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]

 Akzeptierte Antwort

Jos (10584)
Jos (10584) am 10 Feb. 2011

1 Stimme

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

Weitere Antworten (1)

Andrei Bobrov
Andrei Bobrov am 20 Mai 2011

0 Stimmen

B = zeros(sum(any(A,2)),sum(any(A)));
B(:)=A(A~=0);

Kategorien

Mehr zu Interpolation finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by