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

Home » Public Forums » archive » Re: newbie MOMENT question
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
Re: newbie MOMENT question [message #6556] Tue, 16 July 1996 00:00
David Foster is currently offline  David Foster
Messages: 341
Registered: January 1996
Senior Member
demott@denali (Charlotte DeMott) wrote:
>
> Hi,
>
> I want to compute the mean and variance of a set of data points, and
> I'm using the MOMENT procedure to do it. With some fields, the
> variance is quite small (i.e., o(e-03)), so I get floating point
> underflow errors when MOMENT tries to compute the skewness and
> kurtosis. since i don't really care about the skewness and kurtosis,
> how can i get IDL to not worry about this, and continue with the
> rest of the procedure?

Try using

junk = CHECK_MATH( trap=0 )

to disable math traps.

Dave Foster
UCSD Brain Image Analysis Lab
foster@bial1.ucsd.edu
Re: newbie MOMENT question [message #6558 is a reply to message #6556] Mon, 15 July 1996 00:00 Go to previous message
Liam Gumley is currently offline  Liam Gumley
Messages: 473
Registered: November 1994
Senior Member
Charlotte DeMott wrote:
> I want to compute the mean and variance of a set of data points, and
> I'm using the MOMENT procedure to do it. With some fields, the
> variance is quite small (i.e., o(e-03)), so I get floating point
> underflow errors when MOMENT tries to compute the skewness and
> kurtosis. since i don't really care about the skewness and kurtosis,
> how can i get IDL to not worry about this, and continue with the
> rest of the procedure? online help suggests that some combination
> of ON_ERROR and/or CATCH would appropriate, but i haven't been
> able to figure out exactly how to use these two yet. any suggestions?

The following works well for me.

Cheers,
Liam.

pro stddev, array, mean, variance, sigma

;+
; Purpose:
; To compute the mean, variance, and standard deviation
; (also known as RMS, root-mean-square) values for a given dataset.
;
; Usage:
; stddev, array, mean, variance, sigma
;
; Input:
; array array of data values (must have more than one element)
;
; Output:
; mean data mean
; variance data variance
; sigma data standard deviation
;-

;- check number of elements

n = n_elements( array )
if ( n lt 1 ) then message, 'Number of elements less than 1 in STDDEV'

;- compute mean and variance

mean = total( double( array ) ) / double( n )
variance = total( double( array ) ^ 2 ) / double( n ) - mean ^ 2

;- compute sigma if precision ok, otherwise return zero

sigma = 0.0d
test = 1.0d + variance
if ( test gt 1.0d ) then sigma = sqrt( variance )

end
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: size (in bytes) of integer, float, double, etc.
Next Topic: PV-WAVE 6.0 import data

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

Current Time: Wed Oct 08 13:32:09 PDT 2025

Total time taken to generate the page: 0.00536 seconds