Borrar filtros
Borrar filtros

How to remove zero sum row from matrix

6 visualizaciones (últimos 30 días)
Vishal Sharma
Vishal Sharma el 24 de En. de 2017
Respondida: Andrei Bobrov el 24 de En. de 2017
A=[1 2 3 4 5 6;
0 0 1 1 0 1;
0 0 1 0 1 0]
Sum of second and third row if equal to zero, then in new matrix that column is to be excluded. So, the result shall be
A=[3 4 5 6;
1 1 0 1;
1 0 1 0]

Respuesta aceptada

the cyclist
the cyclist el 24 de En. de 2017
Editada: the cyclist el 24 de En. de 2017
colToRemove = sum(A(2:end,:))==0;
A(:,colToRemove) = [];
  1 comentario
the cyclist
the cyclist el 24 de En. de 2017
Edited my answer so that it will sum all rows except the first one.

Iniciar sesión para comentar.

Más respuestas (2)

Roger Stafford
Roger Stafford el 24 de En. de 2017
A = A(:,(A(2,:)+A(3,:)~=0));
  1 comentario
Vishal Sharma
Vishal Sharma el 24 de En. de 2017
Thanks Roger Stafford,,, if there are n rows, please also suggest answer...

Iniciar sesión para comentar.


Andrei Bobrov
Andrei Bobrov el 24 de En. de 2017
A = A(:,sum(A(2:end,:))~=0);

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by