From: burcu on
Dear all,

I'm trying to create a statistics matrix with Matlab but couldn't find a way. Here is the problem. I have a column matrix of 1x1000. 1000 lines includes recurrent 5 different data. So i want to create a 5x5 matrix from this data like:

aa bb cc dd ee
bb ba bc bd be
ca cb cc cd ce
da db dc dd de
ea eb ec ed ee

And this matrix will include the transition rates from one integer to another. To be more clear, first line of the first column will count the number of transition from a to a, second column of second line will count transition number from b to a etc. And my 1x1000 matrix is like the transpose of the matrix below:

[a , a, a, b, a, c, d, a, b, e .....]'

I need to find how many times from one state to another state transition has been occurred in my dataset to find transition probablity briefly.

Thanks in advance
Burcu
From: us on
"burcu " <burcu102(a)hotmail.com> wrote in message <hsc13g$k8q$1(a)fred.mathworks.com>...
> Dear all,
>
> I'm trying to create a statistics matrix with Matlab but couldn't find a way. Here is the problem. I have a column matrix of 1x1000. 1000 lines includes recurrent 5 different data. So i want to create a 5x5 matrix from this data like:
>
> aa bb cc dd ee
> bb ba bc bd be
> ca cb cc cd ce
> da db dc dd de
> ea eb ec ed ee
>
> And this matrix will include the transition rates from one integer to another. To be more clear, first line of the first column will count the number of transition from a to a, second column of second line will count transition number from b to a etc. And my 1x1000 matrix is like the transpose of the matrix below:
>
> [a , a, a, b, a, c, d, a, b, e .....]'
>
> I need to find how many times from one state to another state transition has been occurred in my dataset to find transition probablity briefly.
>
> Thanks in advance
> Burcu

a hint:

help accumarray;

us
From: burcu on
Hi Us,

Thank you very much for the hint but this function doesnt seem to be creating a matrix for transition numbers from one variable to another, rather it's counting the occurrence, making some other functions.
tried to apply this to my problem but no luck.

Burcu

>
> a hint:
>
> help accumarray;
>
> us
From: us on
"burcu " <burcu102(a)hotmail.com> wrote in message <hsc41v$192$1(a)fred.mathworks.com>...
> Hi Us,
>
> Thank you very much for the hint but this function doesnt seem to be creating a matrix for transition numbers from one variable to another, rather it's counting the occurrence, making some other functions.
> tried to apply this to my problem but no luck.
>
> Burcu
>
> >
> > a hint:
> >
> > help accumarray;
> >
> > us

well... ACCUMARRAY typically is used (by most CSSMers) to create transition matrices... and, unless i completely misunderstood what you need...

one of the solutions

v=[2,3,4,3,5,2,3,5,2,3,4,2,1].'; % <- note: col vec
tm=accumarray([v(1:end-1),v(2:end)],1)
%{
% tm =
0 0 0 0 0 % <- eg, no transition 1->
1 0 3 0 0 % <- eg, transition 2->3 occurs three times...
0 0 0 2 2
0 1 1 0 0
0 2 0 0 0
%}

us
From: burcu on
This is exactly what i need:) i have taken v in a different way, now it works. Thank you very much!
Burcu

>
> well... ACCUMARRAY typically is used (by most CSSMers) to create transition matrices... and, unless i completely misunderstood what you need...
>
> one of the solutions
>
> v=[2,3,4,3,5,2,3,5,2,3,4,2,1].'; % <- note: col vec
> tm=accumarray([v(1:end-1),v(2:end)],1)
> %{
> % tm =
> 0 0 0 0 0 % <- eg, no transition 1->
> 1 0 3 0 0 % <- eg, transition 2->3 occurs three times...
> 0 0 0 2 2
> 0 1 1 0 0
> 0 2 0 0 0
> %}
>
> us