How to delete specific lines in a table

5 visualizzazioni (ultimi 30 giorni)
012786534
012786534 il 11 Lug 2016
Commentato: Peter Perkins il 3 Ago 2016
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!

Risposte (2)

James Tursa
James Tursa il 12 Lug 2016
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 il 12 Lug 2016
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 Commento
Peter Perkins
Peter Perkins il 3 Ago 2016
There's no point in converting to a cell array and then back again. James' response shows how to use table subscripting directly.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by