Calculating frequency of values within bins


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calculating frequency of values within bins
# 8  
Old 01-05-2012
hi, big thanks. do u mind, if u briefly walk me through the updated version of your code? I don't fully understood this part of the code.
Code:
m=($1<m)?$1:m
M=(M<$1)?$1:M

thanks!
# 9  
Old 01-05-2012
This part just setup the min (m) and max (M) values taken by $1
Code:
m=($1<m)?$1:m



means :

m=(is $1 lower than m)? if yes,takes $1 : otherwise takes m
This User Gave Thanks to ctsgnb For This Post:
# 10  
Old 01-06-2012
Hi ctsgnb,
Thanks for the replies and help. my apologies, havent get back to u sooner.
# 11  
Old 01-06-2012
Be carefull : all the attempt i posted do different things.

In order to make sure it really fit with your expectations, do not pick them up until you are fully understanding what it does.

If you have any questions, feel free to shoot.
# 12  
Old 01-06-2012
hi ctsgnb, bunch of thanks really. Ive found a code in matlab that does the calculation i wanted. i just dont know how to translate it in unix.
Code:
clear all 
load data 
x=data(:,1); 
y=data(:,2); 
 
topEdge=16; 
botEdge=-16; 
numBins=16; 
 
binEdges=linspace(botEdge, topEdge, numBins+1); 
 
[h, whichbin]=histc(x,binEdges); 
 
for i=1:numBins+1 
    flagBinMembers = (whichbin ==i); 
    binMembers = y(flagBinMembers); 
    binMean(i)= mean(binMembers); 
end

# 13  
Old 01-06-2012
I don't know Matlab, sorry ...
# 14  
Old 01-06-2012
thanks for all your help. anyways, on your last posted code, is there a way to tweak it that instead of bin ranges, it would be linearly spaced bin values. for instance, it would be:
Code:
bin=(9,10,11,12,13,14,15,16,17,18,19,20)

so that it will give a mean of col.2 falling on this linearly spaced values of col.1?the output will then be:
Code:
9- mean of col2 values with col.1 values falling within this bin
10- mean of col2 values with col. 1 values falling within this bin
and so on...

thanks again
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Create bins with totals and percentage

I would like to create bins to get histogram with totals and percentage, e.g. starting from 0. If possible to set the minimum and maximum value in the bins ( in my case value min=0 and max=20 ) Input file 8 5 10 1 11 4 12 4 12 4 13 5 16 7 18 9 16 9 17 7 18 5 19 5 20 1 21 7 (10 Replies)
Discussion started by: jiam912
10 Replies

2. Shell Programming and Scripting

awk to select 2D data bins

I wish to use AWK to do something akin: Select all 2D data with 1<$1<2 and -7.5<$2<-6.5 But it's not working awk 'END {print ($1<=2&&$1>=1&&$2<=-6.5&&$2>=-7.5)}' bla Data: -1.06897 -8.04482 -61.469 -1.13613 -8.04482 -61.2271 -1.00182 -8.04482 -61.2081 -1.06897 -8.13518 -60.8544... (2 Replies)
Discussion started by: chrisjorg
2 Replies

3. Shell Programming and Scripting

Count frequency of unique values in specific column

Hi, I have tab-deliminated data similar to the following: dot is-big 2 dot is-round 3 dot is-gray 4 cat is-big 3 hot in-summer 5 I want to count the frequency of each individual "unique" value in the 1st column. Thus, the desired output would be as follows: dot 3 cat 1 hot 1 is... (5 Replies)
Discussion started by: owwow14
5 Replies

4. UNIX for Dummies Questions & Answers

awk solution for taking bins

Hi all, I'm looking for an awk solution for taking bins of data set. For example, if I have two columns of data that I wish to use for a scatter plot, and it contains 5 million lines, how can I take averages of every 100 points, 1000, 10000 etc... The idea is to take bins of the 5,000,000 points... (7 Replies)
Discussion started by: torchij
7 Replies

5. UNIX for Dummies Questions & Answers

Calculating cumulative frequency using awk

Hi, I wanted to calculate cumulative frequency distribution of my data that involves several arithmetic calls. I did things in excel but its taking me forever. this is what I want to do: var1.txt contains n observations which I have to compute for frequency which is given by 1/n and subsequently... (7 Replies)
Discussion started by: ida1215
7 Replies

6. Shell Programming and Scripting

calculating unique strings values

Hi, Im looking for a script which will calculate the unique strings column 2 & 3 values in a log as mentioned in example eg:- bag 12 12 bag 18 15 bags 15 13 bags 15 14 blazer 24 24 blazer 33 32 boots 19 15 Result should be:- bag 30 27 bags 30 27... (9 Replies)
Discussion started by: Paulwintech
9 Replies

7. Solaris

Redirecting print to optional output bins

Guys We have a HP P4015 laserjet printer with a 5 bin mailbox attached & configured. We can print to the specific output bins from Oracle e-Business suite, however our print output format is incompatible so it prints out random characters instead of the letter content. I have looked... (2 Replies)
Discussion started by: s1977
2 Replies

8. Shell Programming and Scripting

Help with calculating frequency of specific word in a string

Input file: #read_1 AWEAWQQRZZZQWQQWZ #read_2 ZZAQWRQTWQQQWADSADZZZ #read_3 POGZZZZZZADWRR . . Desired output file: #read_1 3 #read_1 1 #read_2 2 #read_2 3 #read_3 6 . . (3 Replies)
Discussion started by: perl_beginner
3 Replies

9. Shell Programming and Scripting

Calculating cumulative frequency

Hi, I have a file containing the frequency's of an element sorted in ascending order. The file looks something like this: #Element Frequency 1 1 2 1 3 1 4 1 5 1 6 ... (5 Replies)
Discussion started by: sajal.bhatia
5 Replies

10. UNIX for Dummies Questions & Answers

Calculating the Hours between two time values

Dear Folks, I want to calculate the elapsed hours between two time columns. I am using timestampdiff method for the same. I am able to get the value. But facing an issue of decimal values. For example the elapsed hours between 09:00:00 and 20:30:00 is coming as 11 instead of 11.5. I am using below... (1 Reply)
Discussion started by: dinesh1985
1 Replies
Login or Register to Ask a Question