필터 지우기
필터 지우기

how to find an empty row in a table

조회 수: 102 (최근 30일)
tiwwexx
tiwwexx 2019년 6월 21일
댓글: Gabor 2021년 3월 4일
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에서 Array Geometries and Analysis에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by