I have a table in which one of the columns is a cell array of text data, and a cell array C that contains a subset of this text. Is there a way to extract from the table only the rows with the text in C?

 採用された回答

Stephen23
Stephen23 2021 年 11 月 19 日

0 投票

Where T is your table and C is your cell array:
idx = ismember(T.NameOfVariable, C)
out = T(idx,:)

その他の回答 (1 件)

Matt J
Matt J 2021 年 11 月 19 日

0 投票

Yes, you can use ismember(...,'rows') to find the indices of the rows.

3 件のコメント

Kim Maria Damiani
Kim Maria Damiani 2021 年 11 月 19 日
Thank you but with
ismember(C,table,'rows')
I got an error that both arguments should be tables. C is not a table, just a column cell array with text, while the table has more variables.
Stephen23
Stephen23 2021 年 11 月 19 日
編集済み: Stephen23 2021 年 11 月 19 日
@Kim Maria Damiani: do not use the whole table, just the variable that you want to compare. Also the order needs to be swapped around in order for it to work correctly:
idx = ismember(T.NameOfVariable, C)
out = T(idx,:)
Kim Maria Damiani
Kim Maria Damiani 2021 年 11 月 19 日
Thank you @Stephen. If you want to move your comment to an answer I can accept.

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

カテゴリ

ヘルプ センター および File ExchangeData Type Identification についてさらに検索

製品

リリース

R2021b

タグ

質問済み:

2021 年 11 月 19 日

回答済み:

2021 年 11 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by