Azzera filtri
Azzera filtri

Delete rows that contains []

13 visualizzazioni (ultimi 30 giorni)
Alfonso Lopez
Alfonso Lopez il 25 Nov 2015
Commentato: Alfonso Lopez il 25 Nov 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

Risposta accettata

Andrei Bobrov
Andrei Bobrov il 25 Nov 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 Commenti
Thorsten
Thorsten il 25 Nov 2015
Or
out = x(~any(cellfun(@isempty,x),2),:)
Alfonso Lopez
Alfonso Lopez il 25 Nov 2015
OMG!! Thanks very much. I was trying to do this almost all morning :)

Accedi per commentare.

Più risposte (1)

Guillaume
Guillaume il 25 Nov 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 Commento
Alfonso Lopez
Alfonso Lopez il 25 Nov 2015
The same result as Andrei suggestion. Thanks very much too :)

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by