Filter löschen
Filter löschen

Delete rows that contains []

13 Ansichten (letzte 30 Tage)
Alfonso Lopez
Alfonso Lopez am 25 Nov. 2015
Kommentiert: Alfonso Lopez am 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

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

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

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by