|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#2
|
|||
|
|||
|
Surely there's a way to do that with awk. awk doesn't have a single function for it of course, since it doesn't make much sense to do a boxcar average on a single line... Let me see if I have the algorithm right. For these points: Code:
1 5 2 6 3 7 4 8 5 9 for a boxcar average of width 3, would you want: Code:
(1+5+2)/3, (5+2+6)/3, (2+6+3)/3, (6+3+7)/3, (3+7+4)/3, (7+4+8)/3, (4+5+5)/3, (8+5+9)/3 ---------- Post updated at 04:22 PM ---------- Previous update was at 04:10 PM ---------- Code:
$ cat data
1
5
2
6
3
7
4
8
5
9
$ cat smooth.awk
BEGIN { WIDTH=3 }
{ DATA[(++N)%WIDTH]=$1 }
(N>=WIDTH) {
V=0
for(X=(N+1); X<=(N+WIDTH); X++)
V+=DATA[X%WIDTH];
print V/WIDTH;
}
$ awk -f smooth.awk data
2.66667
4.33333
3.66667
5.33333
4.66667
6.33333
5.66667
7.33333
4.66667
$Last edited by Corona688; 02-07-2012 at 05:20 PM.. |
| The Following User Says Thank You to Corona688 For This Useful Post: | ||
cosmologist (02-13-2012) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Quote:
![]() I am trying to apply this idea to "degrade" the output of a model resolution. For the sample: $ vi model.dat Code:
3002.000 1.2874e+32 3002.300 1.2898e+32 3002.600 1.2966e+32 3002.900 1.3000e+32 3003.200 1.2997e+32 3003.500 1.2961e+32 3003.800 1.2926e+32 3004.100 1.2909e+32 3004.400 1.2904e+32 3004.700 1.2923e+32 3005.000 1.2970e+32 3005.300 1.3027e+32 3005.600 1.3043e+32 3005.900 1.3028e+32 3006.200 1.2977e+32 3006.500 1.2894e+32 3006.800 1.2802e+32 3007.100 1.2738e+32 3007.400 1.2717e+32 3007.700 1.2728e+32 3008.000 1.2778e+32 I want to "somehow" degrade the resolution of the first column from 0.3 to 3 for the corresponding numbers in the second column something like this: Code:
3002.000 ??? 3005.000 ??? 3008.000 ??? Where the "???" are the numbers I am trying to obtain using the awk script that you suggested but I am not able to get the results |
|
#4
|
|||
|
|||
|
Any thoughts on this... I am still not able to solve it
![]() ![]() ![]() |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
It took you a week to get back to me. It can't be urgent enough for you to break the rules by bumping.
We're not on call, if nobody answers your post immediately, wait! What is the ??? supposed to be? How would I arrive at it? In what way does the code I gave you "not work"? My last two posts were one big question, "do I have the right algorithm", and you never answered me. |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
I am sorry I didn't mean to sound rude, the reason I took a week is that I was trying to figure it out myself first
It is not urgent but I just thought that if more details are needed for my question I can give more details.. I am sorry for that... the second post wasn't only for you, it was for anyone who might have an idea... I am really sorry ![]() |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Don't be sorry, just please answer my questions
They'll help anyone else trying to help you too. |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| awk command to replace ";" with "|" and ""|" at diferent places in line of file | shis100 | Shell Programming and Scripting | 7 | 03-16-2011 08:59 AM |
| Make scipt except from "Y","y" and "yes" to take [Enter] as being "yes" | hakermania | Shell Programming and Scripting | 4 | 12-11-2010 09:24 AM |
| ps -ef | grep "string1" "string2" " "string3" | steve2216 | Shell Programming and Scripting | 11 | 09-03-2010 11:08 AM |
| Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" | Lokesha | UNIX for Dummies Questions & Answers | 4 | 12-20-2007 12:52 AM |
|
|