filter cell array with strings

37 ビュー (過去 30 日間)
Qiana Curcuru
Qiana Curcuru 2021 年 10 月 28 日
編集済み: Ive J 2021 年 10 月 28 日
i have a cell array and want to create a chart by filtering values. basically i want to filter by cat1 and cat3.
For example, i want to pull out all rows where 'cat' is the value for cat1 and then pull out rows where '100' is the value for cat3 (i.e. row 1 and 6 in this case)
my cell array looks like:
{cat1} {cat2} {cat3}
{'cat'} {4} {100}
{'dog'} {4} {100}
{'bird'} {4} {100}
{'cat'} {5} {100}
{'dog'} {4} {200}
{'cat'} {5} {100}

採用された回答

Ive J
Ive J 2021 年 10 月 28 日
編集済み: Ive J 2021 年 10 月 28 日
Try to work with tables, they're more versatile. Also check groupfilter for more advanced filtering schemes.
tab = array2table(string(yourCell))
cat1 cat2 cat3
______ ____ ____
"cat" 4 100
"dog" 4 100
"bird" 4 100
"cat" 5 100
"dog" 4 200
"cat" 5 100
idx = tab.cat1 == "cat" & tab.cat3 == 100;
newTab = tab(idx, :)
cat1 cat2 cat3
_____ ____ ____
"cat" 4 100
"cat" 5 100
"cat" 5 100

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatched Filter and Ambiguity Function についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by