how to exclude a row from a matrix

17 visualizaciones (últimos 30 días)
D.J
D.J el 3 de Oct. de 2018
Comentada: D.J el 3 de Oct. de 2018
Hi all, I need to extract all data from a matrix except for one row (the 3rd from last).
Say for example I have the matrix below and I want to exclude this row: [NAN,7,7] Any idea how to do that? Many thanks
T=[1,2,3;4,5,6;7,8,9;1,2,3;4,5,6;7,8,9; NAN,7,7;4,5,6;7,8,9]
  1 comentario
Bob Thompson
Bob Thompson el 3 de Oct. de 2018
I would suggest using an isnan check. Not entirely sure how it will treat an entire row, but a place to start.
T=[1,2,3;4,5,6;7,8,9;1,2,3;4,5,6;7,8,9; NAN,7,7;4,5,6;7,8,9];
T = T(~isnan(T),:);
I suspect you will need:
T = T(~isnan(T(:,1)),:);

Iniciar sesión para comentar.

Respuesta aceptada

the cyclist
the cyclist el 3 de Oct. de 2018
Assuming that what you want is to exclude any row with a NaN in any position, then either
T = T(all(~isnan(T),2),:);
or
T(any(isnan(T),2),:) = [];
will do the job.
  1 comentario
D.J
D.J el 3 de Oct. de 2018
There was a problem with the first option, but the 2nd one worked perfectly well. Thank you very much.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by