Thread Subject:
how to find the maximum repetitions in string

Subject: how to find the maximum repetitions in string

From: vj

Date: 28 Jul, 2012 21:18:16

Message: 1 of 4

hi,

I have a string inside a cell as follows,

for n=1:7
database{1,n}='vijay';
end
for n=8:11
database{1,n}='someone';
end

the maximum repetitions of the above string is 'vijay'. can someone please help me in obtaining a same result through code.

thanks.

Subject: how to find the maximum repetitions in string

From: dpb

Date: 28 Jul, 2012 21:41:57

Message: 2 of 4

On 7/28/2012 4:18 PM, vj wrote:
> hi,
> I have a string inside a cell as follows,
> for n=1:7
> database{1,n}='vijay';
> end
> for n=8:11
> database{1,n}='someone';
> end
>

If the contents are known,

sum(strfind(database,'vijay')>0)

is the count

If not, will have to iterate to find the values -- unique() would be
good here but it doesn't have a built in parallel for strings that I can
think of ... an auxiliary hash value would be good for that purpose...

--

Subject: how to find the maximum repetitions in string

From: vj

Date: 29 Jul, 2012 00:02:19

Message: 3 of 4

dpb <none@non.net> wrote in message <jv1mb2$i3n$1@speranza.aioe.org>...
> On 7/28/2012 4:18 PM, vj wrote:
> > hi,
> > I have a string inside a cell as follows,
> > for n=1:7
> > database{1,n}='vijay';
> > end
> > for n=8:11
> > database{1,n}='someone';
> > end
> >
>
> If the contents are known,
>
> sum(strfind(database,'vijay')>0)
>
> is the count
>
> If not, will have to iterate to find the values -- unique() would be
> good here but it doesn't have a built in parallel for strings that I can
> think of ... an auxiliary hash value would be good for that purpose...
>
> --


Thank you so much!! It helped!

Subject: how to find the maximum repetitions in string

From: Steven_Lord

Date: 31 Jul, 2012 15:13:02

Message: 4 of 4



"vj " <vijay.easwari@gmail.com> wrote in message
news:jv1kuo$2ng$1@newscl01ah.mathworks.com...
> hi,
> I have a string inside a cell as follows,
> for n=1:7
> database{1,n}='vijay';
> end
> for n=8:11
> database{1,n}='someone';
> end
>
> the maximum repetitions of the above string is 'vijay'. can someone please
> help me in obtaining a same result through code.

You can use UNIQUE to generate a numeric array from your cell array, then
use MODE on that numeric array.

for n=1:7
    database{1,n}='vijay';
end
for n=8:11
    database{1,n}='someone';
end
[C, ~, IC] = unique(database);
mostFrequent = C{mode(IC)}

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
string repeititons vj 28 Jul, 2012 17:19:18
rssFeed for this Thread

Contact us