Is there a dsearchn equivalent for strings?

2 ビュー (過去 30 日間)
Reza Yahyaei
Reza Yahyaei 2020 年 8 月 27 日
コメント済み: Reza Yahyaei 2020 年 12 月 5 日
I have two cell arrays, one is the array I want to find indices of multiple strings. Say q = { 'A', 'B' } and p = { 'H', 'F', ..., 'Z' }. Is there a function that finds the strings and returns their indices like ans = [ 12, 3 ] ? Or the only way is to use a for loop and find(strcmp(...)) which doesn't seem very efficient?

採用された回答

Cris LaPierre
Cris LaPierre 2020 年 8 月 27 日
I think you would have to do it one value at a time.
find(contains(p,q(1)))
There are several functions you could use
  • strfind
  • ismember
  • contains
See this post for more ideas.
  1 件のコメント
Reza Yahyaei
Reza Yahyaei 2020 年 12 月 5 日
I don't remember what happened that I forgot to follow this question (probably my computer got broken) but thanks a lot for your answer.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by