フィルターのクリア

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

4 ビュー (過去 30 日間)
Caglar
Caglar 2018 年 11 月 20 日
回答済み: Guillaume 2018 年 11 月 20 日
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 件のコメント
madhan ravi
madhan ravi 2018 年 11 月 20 日
All the datas in the table has nan values so whats your question?

サインインしてコメントする。

採用された回答

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 Center および File ExchangeCharacters and Strings についてさらに検索

タグ

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by