Delete rows that contains []

22 views (last 30 days)
Alfonso Lopez
Alfonso Lopez on 25 Nov 2015
Commented: Alfonso Lopez on 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

Accepted Answer

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

Sign in to comment.

More Answers (1)

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

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!