フィルターのクリア

Find count of repeated letters (sequence)

1 回表示 (過去 30 日間)
Jothi
Jothi 2013 年 10 月 8 日
回答済み: Walter Roberson 2016 年 12 月 1 日
Sir,
How to find the no. of repeated sequence (letters) in the given sentence.
for example, a="I want THAAAAAT APPPPPLE ):):): totally unprepared";
The No. of repeated sequences are: 3
ie.,
1. THAAAAAT
2. APPPPPLE
3. ):):):
thanks
  4 件のコメント
Walter Roberson
Walter Roberson 2013 年 10 月 9 日
Your #3, ):):): does not have continuously repeated symbols.
If the repeated sequences are to be identified, then why would all of THAAAAAT be output, and not just AAAAA ?
Jothi
Jothi 2013 年 10 月 9 日
:) this symbol indicates one type of emotion symbol (positive emotion).
I don't want the output as string just find the no. of repeated sequences are appeared in the given sentence. ie.,
input is,
a="I want THAAAAAT APPPPPLE ):):): totally unprepared";
output is,
No. of repeated sequences are: 3

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

回答 (2 件)

Cedric
Cedric 2013 年 10 月 8 日
編集済み: Cedric 2013 年 10 月 8 日
Try to understand the following and fine-tune it to your needs:
n = sum( diff([0, diff(a)==0]) == 1 )
In particular, evaluate
diff(a)==0
and see how your problem actually translates into counting clusters of the outcome of diff(a)==0.
  4 件のコメント
Cedric
Cedric 2013 年 10 月 10 日
編集済み: Cedric 2013 年 10 月 10 日
You seem to indicate that one repeated sequence is '):'. As far as I am concerned, there is no simple generic solution if you want to detect repeated, arbitrary patterns. To illustrate,
'AABBCCDDEEFFAABBCCDDEEFF'
Here, repeated patterns are
'AA', 'BB', .., 'FF', 'AABB', 'BBCC', .., 'AABBCC', 'BBCCDD', ..,
'AABBCCDD', 'BBCCDDEE', .., 'AABBCCDDEEFF'
Using regular expressions, we can probably get some solution but it will be prohibitively time consuming.
Sean de Wolski
Sean de Wolski 2013 年 10 月 10 日
Yeah, every emoticon would have to be predefined. For the chatroom we use here there are even word emoticons like (b) which inserts a frosty beer mug or (ply) which inserts an image of a playing card.

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


Walter Roberson
Walter Roberson 2016 年 12 月 1 日
a='I want THAAAAAT APPPPPLE ):):): totally unprepared';
regexp(a, '(.+)\1{2,}', 'match')
ans =
1×3 cell array
'AAAAA' 'PPPPP' '):):):'

カテゴリ

Help Center および File ExchangeNumeric Types についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by