Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.



Re: How to generate 2D Frequency Matrix
Posted:
Dec 3, 2012 1:43 AM


"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, 35, 57) like that and row ways (1 to 5, 510, 1015) 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 ith row and jth column of B you have a total count of the number of rowpairs from A which satisfy the condition that the first element of the pair falls in the ith interval of the first type of grouping and the second element in the jth 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 > ... > n1st interval: u1+(n11)*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 > ... > n2nd interval: u2+(n21)*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 05 x x x x x 510 x x x x x 1015 x x x x x 1520 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(05,510 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.



