Delete rows that contains []

24 vues (au cours des 30 derniers jours)
Alfonso Lopez
Alfonso Lopez le 25 Nov 2015
Commenté : Alfonso Lopez le 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

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (1)

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

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by