How to index into a table with more than 1 variable?

조회 수: 5 (최근 30일)
MKM
MKM 2021년 11월 5일
댓글: MKM 2021년 11월 5일
Hi,
The current problem i have is trying to index into a table using more than 1 variable. I want to be able to show all rows that have "mark" and "paul" in the name column. Here is an example of what i am trying to do:
table = 20x4 (various data here col 4 = to table.name)
a = {'mark', 'paul'};
idx = table(strcmp(table.name, a), :);
I just receieve and errors that says - "Row index exceeds table dimensions."
This method works if i only use one name in the a paramater. Not sure why it wont for more than one.

채택된 답변

Stephen23
Stephen23 2021년 11월 5일
편집: Stephen23 2021년 11월 5일
Where T is your table (do NOT use table as a variable name):
out = T(ismember(T.name,a),:);
  댓글 수: 1
MKM
MKM 2021년 11월 5일
cheers, Stephen. Why does this work and the function i used not?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by