Filter löschen
Filter löschen

Is there a dsearchn equivalent for strings?

1 Ansicht (letzte 30 Tage)
Reza Yahyaei
Reza Yahyaei am 27 Aug. 2020
Kommentiert: Reza Yahyaei am 5 Dez. 2020
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?

Akzeptierte Antwort

Cris LaPierre
Cris LaPierre am 27 Aug. 2020
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 Kommentar
Reza Yahyaei
Reza Yahyaei am 5 Dez. 2020
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by