Find location of exact string

3 ビュー (過去 30 日間)
Tejashree Pawar
Tejashree Pawar 2021 年 3 月 11 日
コメント済み: Tejashree Pawar 2021 年 3 月 12 日
Using this line fo code to find "Sine Delta 2" in my xml file which also contains "Cosine Delta 2" and the code returns locaion for both instead of just for "Sine".
How do i return location of the exact string?
row_idx_SineDelta2 = find(~cellfun('isempty',strfind(data,'sine delta 2')))
  1 件のコメント
Tejashree Pawar
Tejashree Pawar 2021 年 3 月 12 日
Thanks for the reply! that worked

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

採用された回答

Jorg Woehl
Jorg Woehl 2021 年 3 月 11 日
編集済み: Jorg Woehl 2021 年 3 月 11 日
regexp(data, '\<sine delta 2')
The \< indicates that the search string must occur at the beginning of a new word - see MATLAB regexp for the almost limitless possibilities for pattern matching.

その他の回答 (1 件)

Jorg Woehl
Jorg Woehl 2021 年 3 月 11 日
編集済み: Jorg Woehl 2021 年 3 月 11 日
Starting with R2020b, you can use pattern with strfind, which allows you to only find matches if they are preceded by a nonletter character (i.e. if the search string starts a new word):
pat = letterBoundary + 'sine delta 2';
strfind(data, pat)
Note that this is case-sensitive; in your code you are searching for 'sine delta 2', but you mention 'Sine Delta 2' in your introduction...
  2 件のコメント
Tejashree Pawar
Tejashree Pawar 2021 年 3 月 11 日
Thanks! I am using Matlab2019b for this. Any command or function i can use with this version?
Jorg Woehl
Jorg Woehl 2021 年 3 月 11 日
Yes, I'll add it as a separate answer...

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

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by