フィルターのクリア

How to make a connection between a key word and a binary digit?

1 回表示 (過去 30 日間)
jojototo
jojototo 2017 年 2 月 4 日
コメント済み: Walter Roberson 2017 年 4 月 4 日
I have a text 'mail.txt' and I chose a key word 'good'which is repeated 10 times in the text,I have generated a random binary number consists of 10 digits 0100111011 ,the first occurrence of the word 'good' meets the first digit'0' the second occurrence meets digit'1' and so on,How to achieve this and also to say if the the digit is '1' replace 'good'with 'bad' ,else no changes,can I have your help please.

採用された回答

Walter Roberson
Walter Roberson 2017 年 2 月 4 日
strfind() 'good', giving back a vector of starting indices. Use the binary vector to select elements out of that array. Make the replacement at each remaining location.
Hint: try looping backwards
  11 件のコメント
jojototo
jojototo 2017 年 4 月 4 日
Hi , the code works,but there is a problm that when the word that I want to replace it is a part of another word"like 'the' in 'there,these,rather'"the letters of 'the' in these words also replaced ,I want only the word "the" to be replaced. I tried this code instead of strfind but also doesn't work >>idx = regexpi(A, 't[h]+e'); thanks for your efforts.
Walter Roberson
Walter Roberson 2017 年 4 月 4 日
To go further, you need to define what a "word" is. In English that is not easy.
The below is an example I used in 2008 for someone wanting to separate out paragraphs. Which are the words in this?
Mr. Todd E. Jones gave $3000. (!) in nickels, dimes, etc. to his
No. 1 son at 4 7th Ave. N., NY. NY. USA., who exclaimed "What joy!
Now I can buy 3 lbs. of St. Tropiz bananas... or can I?!"

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by