Find count of repeated letters (sequence)
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Walter Roberson
am 9 Okt. 2013
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 ?
Antworten (2)
Cedric
am 8 Okt. 2013
Bearbeitet: Cedric
am 8 Okt. 2013
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 Kommentare
Cedric
am 10 Okt. 2013
Bearbeitet: Cedric
am 10 Okt. 2013
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
am 10 Okt. 2013
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
am 1 Dez. 2016
a='I want THAAAAAT APPPPPLE ):):): totally unprepared';
regexp(a, '(.+)\1{2,}', 'match')
ans =
1×3 cell array
'AAAAA' 'PPPPP' '):):):'
0 Kommentare
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!