Find index for mx1 cell with specific string

I have a mx1 cell in A table as Scenario column. I want to find the index matching the string 'Scenario #' using following:
Scenario_list=A.Scenario(Scenario==['Scenario 20']);
Received a "Error using == Matrix dimensions must agree." error message.

 채택된 답변

Stephen23
Stephen23 2018년 6월 29일
편집: Stephen23 2018년 6월 29일

0 개 추천

For comparing a cell array of char vectors and a char vector you have to use strcmp, or strcmpi, or strncmp, etc:
idx = strcmp(A.Scenario,'Scenario 20')
The == operator only works for string arrays:
Do not confuse character vectors or character arrays with string arrays:

추가 답변 (1개)

Adam Danz
Adam Danz 2018년 6월 29일
편집: Adam Danz 2018년 6월 29일

0 개 추천

Replace
Scenario==['Scenario 20']
with
strcmp(Scenario,'Scenario 20')
If you'd like to ignore case, use strcmpi().

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2018년 6월 29일

댓글:

2018년 7월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by