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

Home » Public Forums » archive » Re: Oooh...! It's harder than I thought!! To get average of each line using only meaningful data
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Oooh...! It's harder than I thought!! To get average of each line using only meaningful data [message #54949 is a reply to message #54948] Tue, 24 July 2007 05:47 Go to previous messageGo to previous message
Conor is currently offline  Conor
Messages: 138
Registered: February 2007
Senior Member
On Jul 24, 5:47 am, weitk...@esrf.fr wrote:
> On Jul 24, 10:32 am, Ingo von Borstel <newsgro...@planetmaker.de>
> wrote:
>
>> where_notzero = WHERE(data_arr NE 0,n_notzero)
>> average = total(data_arr) / n_notzero
>
> Or simply,
>
> average = TOTAL(data_arr) / TOTAL(data_arr NE 0).
>
> Cheers,
> Timm

It seems to me that the above two examples both find the average over
the entire data array, not each row individually. To do that, I would
do something like this:

totals = total(data_arr,1)/total(data_arr<1,1)

total(data_arr,1) returns a row vector where each element is the total
of a single line of data. total(data_arr<1,1) does essentially the
same thing, but first it imposes a ceiling on the array, so that no
value is greater than 1. Then, when you total across a line, what you
get is the total number of non-zero elements. So, you are dividing
the sum of every line by the number of non-zero elements in every line
(the average). The result is a row vector, not a column vector
though. If that's a problem, you can always:

totals = reform(totals,1,numlines)

Also, I've assumed that data_arr is the same thing as in the above
examples. I would make a slight change to the reading part of the
above example though. I would change this line:

FOR i=0,n_datastrgs-1 DO data_arr[i] = DOUBLE(data_strgs[i])

To this:

data_arr = double(data_strgs)

There's no need for the for loop.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: IDL crashing on call of TV - solved
Next Topic: Re: recommendations for curve fitting

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

Current Time: Fri Oct 10 20:51:51 PDT 2025

Total time taken to generate the page: 0.94283 seconds