Effacer les filtres
Effacer les filtres

Cutting rows and columns from a matrix

1 vue (au cours des 30 derniers jours)
Franco
Franco le 10 Fév 2011
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]

Réponse acceptée

Jos (10584)
Jos (10584) le 10 Fév 2011
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

Plus de réponses (1)

Andrei Bobrov
Andrei Bobrov le 20 Mai 2011
B = zeros(sum(any(A,2)),sum(any(A)));
B(:)=A(A~=0);

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by