Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: How to generate 2D Frequency Matrix
Replies: 8   Last Post: Dec 3, 2012 8:54 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
S Ehtesham Al Hanif

Posts: 9
Registered: 12/1/12
Re: How to generate 2D Frequency Matrix
Posted: Dec 3, 2012 1:43 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Roger Stafford" wrote in message <k9gji4$mg$1@newscl01ah.mathworks.com>...
> "S Ehtesham Al Hanif" <ehtesham.buet@gmail.com> wrote in message <k9g62s$h7b$1@newscl01ah.mathworks.com>...
> > I have a matrix A( i x j) like this which has row=i=1400 numbers and column=j=2.
> >
> > As this matrix both column vectors has repetition of no such as 1's 15 times, 2's 18 times etc. So, I want to transfer that matrix into a single matrix which will be a frequency matrix of that one.
> >
> > Such as: if i think about a table then on column i divided it into (1 to 3, 3-5, 5-7) like that and row ways (1 to 5, 5-10, 10-15) and which matrix i want that should fulfill both condition in a same row at the same time and count how many times it repeats and put that on that space or location.
> >
> > Suppose, If i have row ways 10 group and column ways 5 groups then my final frequency matrix will be (10 x 5)
> >
> > Please If anybody help me to sort it out! It will be great help for me!

> - - - - - - - - - -
> If I understand you correctly, you want to produce a "frequency" matrix B from A such that in the i-th row and j-th column of B you have a total count of the number of row-pairs from A which satisfy the condition that the first element of the pair falls in the i-th interval of the first type of grouping and the second element in the j-th interval of the second type of grouping. In each grouping the intervals are all to be of the same length, (an important assumption in what follows.) Is that interpretation correct?
>
> If so, you need to define your two types of groupings. Let u1 and d1 define the first grouping of n1 intervals by
>
> 1st interval: u1 <= a1 < u1+d1
> 2nd interval: u1+d1 <= a1 < u1+2*d1
> 3rd interval: u1+2*d1 <= a1 < u1+3*d1
> ...
> n1-st interval: u1+(n1-1)*d1 <= a1 < u1+n1*d1
>
> where a1 is an element of the first column of A. Similarly let u2 and d2 define the second group of n2 intervals by
>
> 1st interval: u2 <= a2 < u2+d2
> ...
> n2-nd interval: u2+(n2-1)*d2 <= a2 < u2+n2*d2
>
> where a2 is the corresponding second element of a pair from A.
>
> Defining u1, d1, n1, u2, d2, and n2 is your task. In the method that follows it is important that these be defined such that the two elements of each pair from A fall somewhere within the above two types of intervals with the upper "less than" inequalities strictly satisfied.
>
> Then do this:
>
> B = accumarray([floor((A(:,1)-u1)/d1+1),floor((A(:,2)-u2)/d2+1)],1,[n1,n2]);
>
> This should give you an n1 by n2 matrix of pair counts.
>
> Roger Stafford


Hi Roger

Actually, I have data?s like below:
A B
4.8 1.34
9.5 1.30
13.8 1.21
18.5 1.30
23.0 1.25
27.2 1.16
27.9 0.18
29.1 0.36
33.3 1.16
34.9 0.45
36.1 0.31
36.2 0.04
35.6 -0.18
34.6 -0.27
33.6 -0.27
32.8 -0.22
31.9 -0.27
27.4 -1.25
24.0 -0.94
24.0 0.00

Now I want to generate a matrix with frequency distribution like below
A\B -1 -2 0 1 2
0-5 x x x x x
5-10 x x x x x
10-15 x x x x x
15-20 x x x x x

These x (frequency) I have to find out and these, x will be a (mxn) matrix based on those condition. Each x will have to fulfill A(0-5,5-10 etc) & B(-1,-2,0, etc) matrix at a same time then when full column matrix complete then the resultant X(mxn) matrix with overall frequency.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.