Effacer les filtres
Effacer les filtres

Index table with cell array

21 vues (au cours des 30 derniers jours)
Kim Maria Damiani
Kim Maria Damiani le 19 Nov 2021
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?

Réponse acceptée

Stephen23
Stephen23 le 19 Nov 2021
Where T is your table and C is your cell array:
idx = ismember(T.NameOfVariable, C)
out = T(idx,:)

Plus de réponses (1)

Matt J
Matt J le 19 Nov 2021
Yes, you can use ismember(...,'rows') to find the indices of the rows.
  3 commentaires
Stephen23
Stephen23 le 19 Nov 2021
Modifié(e) : Stephen23 le 19 Nov 2021
@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 le 19 Nov 2021
Thank you @Stephen. If you want to move your comment to an answer I can accept.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Tags

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by