Selecting rows from a table using a column that includes Nan elements
2 次查看(过去 30 天)
显示 更早的评论
Hello,
I have a table and I am using one of it's columns to select rows. All data is char. Normally I can use this,
ismember(my_table{:,6},{'SelectThese'}) %6 is column number
However, due to limitations of 'ismember', it does not work if column has NaN elements.
It says,
Error using cell/ismember (line 34)
Input A of class cell and input B of class cell must be cell arrays of character vectors, unless one is a character
vector.
Unfortunately, ismissing ignores those nans and isnan does not work on tables or cell arrays.
How can I select my rows then?
To put it differently, a column in my table has chars and nans as data:
my_table.column(1)='veri1'; my_table.column(2)='veri2'; my_table.column(3)='veri2'; my_table.column(4)=0/0; %0/0=Nan
and I want to select rows that has 'veri2' as column data.
I atached my table.
1 个评论
采纳的回答
Guillaume
2018-11-20
The real question is why have you got NaN in a column of text. It's never a good idea to mix text with numeric. The best thing would be to fix the table creation so that '' gets into that column instead of NaN. Otherwise, fix it after the fact:
%note that the shortcircuiting behaviour of && is used below to prevent calling isnan on a char array. It cannot be replaced by &.
my_table{cellfun(@(t) isnumeric(t) && isnan(t), my_table{:, 6}), 6} = {''}; %replace NaN entries by empty string.
You can then use ismember as usual.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numeric Types 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!