comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » problem in finding average for every 100 points in a data set.
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
problem in finding average for every 100 points in a data set. [message #87418] Fri, 31 January 2014 18:26 Go to next message
arsood is currently offline  arsood
Messages: 1
Registered: January 2014
Junior Member
Hi,
I have a data of B =300,000 and I want to find average for every 100 points. (eg, 0-100,101-200,201-300 and so on)
I am using the following code
pro at
restore,'/home/coefficient.sav'
nn = 300000
BB = y3^2+y4^2
B= sqrt(BB)
bb = fltarr(long(nn-101))
For i = long(0), long(nn-101),long(100) do begin
bb(i) = mean(B(i:i+200))
endfor
print,bb
end
When I compile the program it prints zero along with nonzero values. so further I have o use another command for nonzero values
print,bb(where(bb ne 0.0))

Can please anybody tell me is my code correct and how can I print all non zero values in first place??

Thanks
ARSOOD
Re: problem in finding average for every 100 points in a data set. [message #87422 is a reply to message #87418] Fri, 31 January 2014 20:34 Go to previous messageGo to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Friday, January 31, 2014 9:26:48 PM UTC-5, arsood wrote:
> Can please anybody tell me is my code correct and how can I print all non zero values in first place??

This code:
> bb(i) = mean(B(i:i+200))
is incorrect because you are averaging 201 points, not 100 points. Also, the variable I increases by 100 every step, so you only put valid data in B[] every 100th point.

If you are going to do it with a loop, then keep track of input array and output array separately, like this.

i = 0L
j = 0L
while i LT (n-100) do begin
bb(j) = mean(b(i:i+99))
i = i + 100 ;; Advance to next block in B
j = j + 1 ;; Advance to next position in BB
endwhile
n_output = j
print, bb(0:n_output-1)

CM
Re: problem in finding average for every 100 points in a data set. [message #87431 is a reply to message #87418] Sun, 02 February 2014 22:52 Go to previous message
Moritz Fischer is currently offline  Moritz Fischer
Messages: 32
Registered: June 2013
Member
To get the means over blocks of 100 values, I'd reform 'B' ( 100 values
each line, thus 3,000 lines), and then get the means along each line:

bb = mean( reform( B, 100, 3000 ), DIM = 1 )



Am 01.02.2014 03:26, schrieb arsood:
> Hi,
> I have a data of B =300,000 and I want to find average for every 100 points. (eg, 0-100,101-200,201-300 and so on)
> I am using the following code
> pro at
> restore,'/home/coefficient.sav'
> nn = 300000
> BB = y3^2+y4^2
> B= sqrt(BB)
> bb = fltarr(long(nn-101))
> For i = long(0), long(nn-101),long(100) do begin
> bb(i) = mean(B(i:i+200))
> endfor
> print,bb
> end
> When I compile the program it prints zero along with nonzero values. so further I have o use another command for nonzero values
> print,bb(where(bb ne 0.0))
>
> Can please anybody tell me is my code correct and how can I print all non zero values in first place??
>
> Thanks
> ARSOOD
>
>
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: cgplotting points with error bars
Next Topic: extra lines in colorbar

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:46:53 PDT 2025

Total time taken to generate the page: 0.00476 seconds