Borrar filtros
Borrar filtros

picking rows which has negative element.

6 visualizaciones (últimos 30 días)
Kaushik
Kaushik el 17 de Abr. de 2013
hi, i have a matrix which can have negative elements. is ther eq quick and efficient way to pick the rows if any element in the row has negative values.
Thanks

Respuesta aceptada

Iman Ansari
Iman Ansari el 17 de Abr. de 2013
Hi
a=randn([5 5])+1
Nrows=sum(a<0,2);
a(Nrows>0,:)
  2 comentarios
Kaushik
Kaushik el 17 de Abr. de 2013
this is not correct. because the sum of the elements along dimension 2 can be positive while there exists a negative element present. may be i should clarify my question. i want to pick a row if the row has a negative element (the row may have mixture of positive and negative elements)
Iman Ansari
Iman Ansari el 17 de Abr. de 2013
sum(a<0,2) is number of negative elements in each row. a<0 is one for negative values and 0 for others.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Shifting and Sorting 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