Asked by Jothi
on 8 Oct 2013

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

*No products are associated with this question.*

Answer by Cedric Wannaz
on 8 Oct 2013

Edited by Cedric Wannaz
on 8 Oct 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`.

Jothi
on 10 Oct 2013

sir,

the repeated sequences are more than two.

AAAAA

PPPPP

ll - not more than two (in 'totally')

thank you sir.

Cedric Wannaz
on 10 Oct 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
on 10 Oct 2013

**(b)** which inserts a frosty beer mug or **(ply)** which inserts an image of a playing card.

Log in to comment.

Answer by Walter Roberson
on 1 Dec 2016

a='I want THAAAAAT APPPPPLE ):):): totally unprepared';

regexp(a, '(.+)\1{2,}', 'match')

ans = 1×3 cell array 'AAAAA' 'PPPPP' '):):):'

Log in to comment.

Related Content

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today
## 4 Comments

## Walter Roberson (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/89487-find-count-of-repeated-letters-sequence#comment_172918

'THAAAAAT' is not a repeated sequence. It contains a repeated sequence.

Could you confirm that the sequences can be more than just adjacent letters such as the A's in THAAAAAT ? The '):' repeating as a unit is intended to be noticed?

## Jothi (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/89487-find-count-of-repeated-letters-sequence#comment_173181

sir,

Repeated sequence is not an adjacent letter. It can be any letter or special character continuously repeated more than two times.

ie., In the word THAAAAAT a letter A is continuously repeated more than two times.

similarly, In the word APPPPPLE a letter P is continuously repeated more than two times.

how to find this.

thank you.

## Walter Roberson (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/89487-find-count-of-repeated-letters-sequence#comment_173182

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 (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/89487-find-count-of-repeated-letters-sequence#comment_173210

:) 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

Log in to comment.