Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Find Recurrence in matrix.

Subject: Find Recurrence in matrix.

From: Atakan

Date: 7 Oct, 2010 07:51:07

Message: 1 of 6

I could not find in MATLAB HELP function that easy way to calculate recurrence in data.


For instance ;

a=[1,2,3,4,5,6,2,3,4,2,3,4,5,1,2,1,2,3,4,5,6,4] ı want to calculate recurrence of 4 ,ı am curious about that matlab has special function for calculate recurrance

recurrence for 4 is 5
recurrance for 3 is 4
recurrance for 1 is 3

Waiting your answers...with best regard :)

Subject: Find Recurrence in matrix.

From: Grzegorz Knor

Date: 7 Oct, 2010 08:39:05

Message: 2 of 6

"Atakan " <cesimkaol@gmail.com> wrote in message <i8ju5b$nhg$1@fred.mathworks.com>...
> I could not find in MATLAB HELP function that easy way to calculate recurrence in data.
>
>
> For instance ;
>
> a=[1,2,3,4,5,6,2,3,4,2,3,4,5,1,2,1,2,3,4,5,6,4] ı want to calculate recurrence of 4 ,ı am curious about that matlab has special function for calculate recurrance
>
> recurrence for 4 is 5
> recurrance for 3 is 4
> recurrance for 1 is 3
>
> Waiting your answers...with best regard :)

DOC UNIQUE, REPMAT, BSXFUN.

For example:
u = unique(a);
u2 = repmat(u',1,length(a));
[u' sum(bsxfun(@eq,u2,a),2)]

Grzegorz

Subject: Find Recurrence in matrix.

From: Ali Can ARIK

Date: 7 Oct, 2010 08:58:05

Message: 3 of 6

Following command finds the recurrence for 4 in the matrix a.
length(find(a==4))

"Grzegorz Knor" <gknor@o2.pl> wrote in message <i8k0v9$14l$1@fred.mathworks.com>...
> "Atakan " <cesimkaol@gmail.com> wrote in message <i8ju5b$nhg$1@fred.mathworks.com>...
> > I could not find in MATLAB HELP function that easy way to calculate recurrence in data.
> >
> >
> > For instance ;
> >
> > a=[1,2,3,4,5,6,2,3,4,2,3,4,5,1,2,1,2,3,4,5,6,4] ı want to calculate recurrence of 4 ,ı am curious about that matlab has special function for calculate recurrance
> >
> > recurrence for 4 is 5
> > recurrance for 3 is 4
> > recurrance for 1 is 3
> >
> > Waiting your answers...with best regard :)
>
> DOC UNIQUE, REPMAT, BSXFUN.
>
> For example:
> u = unique(a);
> u2 = repmat(u',1,length(a));
> [u' sum(bsxfun(@eq,u2,a),2)]
>
> Grzegorz

Subject: Find Recurrence in matrix.

From: Matt J

Date: 7 Oct, 2010 13:18:03

Message: 4 of 6

"Atakan " <cesimkaol@gmail.com> wrote in message <i8ju5b$nhg$1@fred.mathworks.com>...
> I could not find in MATLAB HELP function that easy way to calculate recurrence in data.
=====


This is what HISTC was made for


Recurrences=histc(a,1:max(a)),

Subject: Find Recurrence in matrix.

From: Roger Stafford

Date: 7 Oct, 2010 16:14:05

Message: 5 of 6

"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <i8khab$8hp$1@fred.mathworks.com>...
> "Atakan " <cesimkaol@gmail.com> wrote in message <i8ju5b$nhg$1@fred.mathworks.com>...
> > I could not find in MATLAB HELP function that easy way to calculate recurrence in data.
> .....
> Recurrences=histc(a,1:max(a)),
- - - - - - - -
  If the 'edges' arguments for 'histc' are not known in advance, you can do this instead:

 u = sort(a);
 p = find([true,diff(a)~=0;true]);
 b = [u(p(1:end-1));diff(p)];

The first row in 'b' gives the unique values in 'a' in ascending order and the second row gives their corresponding counts.

Roger Stafford

Subject: Find Recurrence in matrix.

From: Roger Stafford

Date: 8 Oct, 2010 01:14:05

Message: 6 of 6

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i8krkd$k14$1@fred.mathworks.com>...
> .......
> u = sort(a);
> p = find([true,diff(a)~=0;true]); % <-- Wrong!!
> b = [u(p(1:end-1));diff(p)];
> ......
- - - - - - - - - -
  There is a typo in that suggestion of mine. The three lines should read:

 u = sort(a);
 p = find([true,diff(u)~=0;true]);
 b = [u(p(1:end-1));diff(p)];

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

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.

Contact us