フィルターのクリア

Find index for mx1 cell with specific string

1 回表示 (過去 30 日間)
Ivy Chen
Ivy Chen 2018 年 6 月 29 日
コメント済み: Ivy Chen 2018 年 7 月 2 日
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 件のコメント
Ivy Chen
Ivy Chen 2018 年 7 月 2 日
Great, thanks!

サインインしてコメントする。

その他の回答 (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 Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by