Find index for mx1 cell with specific string

1 次查看(过去 30 天)
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
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
Replace
Scenario==['Scenario 20']
with
strcmp(Scenario,'Scenario 20')
If you'd like to ignore case, use strcmpi().

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by