How to delete specific lines in a table

Hello all, Let's say I have a table A with 15 variables. In this table, I have variable B which contains a weird mix of numbers, empty cells and symbols like so:
B = [1, '' , 14, '(' , 2, 9, '}', '']
Now, I want to delete every row in the entire table where variable B is either empty or not a number. Any ideas? Thanks all!

답변 (2개)

James Tursa
James Tursa 2016년 7월 12일

1 개 추천

E.g., assuming variable B is really a cell array since you stated it had mixed numeric and character data:
x = ~cellfun(@isnumeric,A.B) | cellfun(@isempty,A.B);
A(x,:) = [];
Azzi Abdelmalek
Azzi Abdelmalek 2016년 7월 12일

0 개 추천

Look at this example
B = {1, '' , '14b', '(' , 2, 9, '}', ''}'
A=num2cell(ones(size(B)))
C=cell2table([A B],'variablenames',{'A','B'})
k=table2cell(C)
idx=cellfun(@(x) isnumeric(x),k(:,2))
k=k(idx,:)
out=cell2table(k)

댓글 수: 1

Peter Perkins
Peter Perkins 2016년 8월 3일
There's no point in converting to a cell array and then back again. James' response shows how to use table subscripting directly.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Tables에 대해 자세히 알아보기

태그

질문:

2016년 7월 11일

댓글:

2016년 8월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by