Filter contents of a table

5 ビュー (過去 30 日間)
Deepa Maheshvare
Deepa Maheshvare 2019 年 12 月 7 日
回答済み: dpb 2019 年 12 月 7 日
I've the following table
tbl = table(['1'; '2'; '3'; '4'; '5'; '6'],['1'; '3'; '2'; '2'; '4'; '1'],'VariableNames', {'name', 'value'})
I would like to filter rows that don't have 'value' 3 and 4.
Expected result:
tbl = table(['1'; '3'; '4'; '6'],['1'; '2'; '2';'1'],'VariableNames', {'name', 'value'})
Any suggestions on how this can be done?

採用された回答

dpb
dpb 2019 年 12 月 7 日
Why are numeric values entered as text/characters?
ix=~ismember(str2num(tbl.value),[3 4]);
tbl=tbl(ix,:);
If the real question is for table that is using nonnumeric character data, then use one of the string search functions instead. For the actual question, I'd strongly suggest either build the table as numeric to begin with or immediately convert to double.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by