Index table with cell array

조회 수: 16 (최근 30일)
Kim Maria Damiani
Kim Maria Damiani 2021년 11월 19일
답변: Stephen23 2021년 11월 19일
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