how to find an empty row in a table

84 次查看(过去 30 天)
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!

采纳的回答

Matt J
Matt J 2019-6-21
编辑:Matt J 2019-6-21
loc=cellfun('isempty', yourTable{:,'column1'} );
yourTable(loc,:)=[]
  3 个评论
Gabor
Gabor 2021-3-4
编辑:Gabor 2021-3-4
It is a table and a column contains numbers instead of strings and this is the error I get:
Error using cellfun
cellfun works only on cells.
Gabor
Gabor 2021-3-4
For me it works if I convert the table to cell and I use the column number in the script:
yourTable2=table2cell(yourTable);
loc=cellfun('isempty', yourTable2{:,1} );
I hope it helps someone.

请先登录,再进行评论。

更多回答(1 个)

Guillaume
Guillaume 2019-6-21
Even simpler, and probably faster, use the table tools (rather than cell array tools):
yourtable = rmmissing(yourtable)
  1 个评论
Matt J
Matt J 2019-6-21
编辑:Matt J 2019-6-21
Unfortunately, rmmising doesn't seem to recognize the empty matrix [] as a missing data marker, so the table would have to be reformatted.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by