Find index for mx1 cell with specific string

1 visualización (últimos 30 días)
Ivy Chen
Ivy Chen el 29 de Jun. de 2018
Comentada: Ivy Chen el 2 de Jul. de 2018
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.

Respuesta aceptada

Stephen23
Stephen23 el 29 de Jun. de 2018
Editada: Stephen23 el 29 de Jun. de 2018
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:

Más respuestas (1)

Adam Danz
Adam Danz el 29 de Jun. de 2018
Editada: Adam Danz el 29 de Jun. de 2018
Replace
Scenario==['Scenario 20']
with
strcmp(Scenario,'Scenario 20')
If you'd like to ignore case, use strcmpi().

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by