MATLAB Answers

tiwwexx
0

how to find an empty row in a table

Asked by tiwwexx
on 21 Jun 2019
Latest activity Edited by Matt J
on 21 Jun 2019
Hello, I'm trying to get rid of a certain row in a single column table that only has a []. for example if I have a table.
column 1
row1 | 'hey' |
row2 | 'hey' |
row3 | [ ] |
how can I get it to be
column 1
row1 | 'hey' |
row2 | 'hey' |
I have a code that works but for larger tables it's extreemely slow.
yee = "original table";
yee1=table;
for n=1:numel(yee)
if isa(yee{n},'char')
bus=yee(n);
yee1 = [yee1 ; bus];
end
end
I feel like there's a lot more efficient ways to do this. Thanks for any help!

  0 Comments

Sign in to comment.

Products


Release

R2019a

2 Answers

Answer by Matt J
on 21 Jun 2019
Edited by Matt J
on 21 Jun 2019
 Accepted Answer

loc=cellfun('isempty', yourTable{:,'column1'} );
yourTable(loc,:)=[]

  1 Comment

Worked awesome! Thank you!

Sign in to comment.


Answer by Guillaume
on 21 Jun 2019

Even simpler, and probably faster, use the table tools (rather than cell array tools):
yourtable = rmmissing(yourtable)

  1 Comment

Matt J
on 21 Jun 2019
Unfortunately, rmmising doesn't seem to recognize the empty matrix [] as a missing data marker, so the table would have to be reformatted.

Sign in to comment.