How do I determine the index for a specific character string based on its relationship with another character string in the same column?

조회 수: 5 (최근 30일)
I have an edf file called 'eventData' with one column of strings (similar to the example shown below). I would like to pull out the indices that idenfity the first instance of the word 'Help' that occurs before the word 'Shoe' appears, and then for all of those identified indices to be saved into a one column double. The problem is that sometimes the word 'Help' occurs in other instances. So in the example below, I would like to pull out the indices for 1 and 11, but not 7. Thank you so much!
1 Help
2 Run
3 Run
4 Run
5 Shoe
6 Sun
7 Help
8 Run
9 Run
10 Sun
11 Help
12 Run
14 Run
15 Shoe
16 Sun

답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 10월 30일
You'd need to perform the following procedures:
  • DATA import (data read) into MATLAB workspace. Advise to use readtable()
  • Employ MATLAB fcn strcmp()
  • And use logical indexing and obtain all indexes w.r.t your search
  댓글 수: 1
Monique Chatterton
Monique Chatterton 2021년 10월 30일
편집: Monique Chatterton 2021년 10월 30일
The issue is that I don't know how to do the conditional searching, where I am only interested in obtaining the index of the word help in some cases and not others (details in my question). I already have the data imported.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by