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일

1 개 추천

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개)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2020년 8월 27일

댓글:

2020년 12월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by