Selecting rows from a table using a column that includes Nan elements

4 次查看(过去 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.

采纳的回答

Guillaume
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 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by