Index table with cell array

21 次查看(过去 30 天)
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
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
Yes, you can use ismember(...,'rows') to find the indices of the rows.
  3 个评论
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by