Delete rows that contains []

10 visualizaciones (últimos 30 días)
Alfonso Lopez
Alfonso Lopez el 25 de Nov. de 2015
Comentada: Alfonso Lopez el 25 de Nov. de 2015
Hi
I would like to delete rows that contains [ ].
Thanks very much.
[ ] 1 NaN
[ ] 1 NaN
[ ] 1 NaN
[ ] 1 NaN
[ ] 1 0
'o_c' 1 1
'w_c' 1 1

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 25 de Nov. de 2015
x = {[ ] 1 NaN
[ ] 1 NaN
[ ] 1 NaN
[ ] 1 NaN
[ ] 1 0
'o_c' 1 1
'w_c' 1 1};
out = x(~any(cellfun(@(x)isempty(x),x),2),:);
  2 comentarios
Thorsten
Thorsten el 25 de Nov. de 2015
Or
out = x(~any(cellfun(@isempty,x),2),:)
Alfonso Lopez
Alfonso Lopez el 25 de Nov. de 2015
OMG!! Thanks very much. I was trying to do this almost all morning :)

Iniciar sesión para comentar.

Más respuestas (1)

Guillaume
Guillaume el 25 de Nov. de 2015
c = {[] 1 NaN
[] 1 NaN
[] 1 NaN
[] 1 NaN
[] 1 0
'o_c' 1 1
'w_c' 1 1};
You get the cells of the cell array that are empty by using isempty on each cell. You can use cellfun to check each cell. You can then use any on each row (2nd dimension) of the cell array to delete rows that have any cell empty:
c(any(cellfun(@isempty, c), 2), :) = []
  1 comentario
Alfonso Lopez
Alfonso Lopez el 25 de Nov. de 2015
The same result as Andrei suggestion. Thanks very much too :)

Iniciar sesión para comentar.

Categorías

Más información sobre NaNs 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