Prev Go to previous topic
Next Go to next topic
 Last Post 30 May 2017 11:33 AM by  David Starbuck Issues with the MEAN function  1 Replies Sort: Oldest First Most Recent First
 You are not authorized to post a reply.
 Author Messages

SH

New Member

Posts:7

 28 May 2017 09:54 AM I am stymied by something that IDL is doing in my code, and I cannot explain it. I am calculating the mean (average) of a defined subset of an array (using an index defined by the where function), and I am printing out the mean as well as the number of elements in the subset for which a certain condition is met. If no element meets the condition (index = -1) , I would expect the mean to come out as NaN. However, IDL always returns a number. I thought something was wrong in my elaborate code, but then I did the very simple example below, and I cannot explain what is going on at the seventh prompt! It seems to be a bug, as the same thing using standard deviation (STDDEV function) instead of the mean does return NaN. Any workaround? IDL> data=[1,2,3,4,5,6,7,8,9] IDL> m=mean(data) IDL> print, m 5.00000 IDL> index=where(data gt 10) IDL> print, index -1 IDL> m=mean(data[index]) IDL> print, m 9.00000 IDL> m=mean(data) IDL> print, m 5.00000 IDL> index=where (data le 2) IDL> m=mean(data[index]) IDL> print, m 1.50000

David Starbuck

Basic Member

Posts:121

 30 May 2017 11:33 AM If the index is "-1", IDL will return the last element in an array: IDL> a = [2,3,4,5] IDL> a[-1] 5 This is shorthand notation for SIZE-1, for example: IDL> a[N_ELEMENTS(a)-1] 5 This is discussed on the following help page: http://www.harrisgeospatial.com/doc...anges.html My recommendation is to use the NULL keyword when calling the WHERE function. For example: IDL> data=[1,2,3,4,5,6,7,8,9] IDL> m=mean(data) IDL> index=where(data gt 10, /NULL) IDL> m=mean(data[index]) % TOTAL: Variable is undefined: X. % Execution halted at: \$MAIN\$ IDL> data[index] !NULL -David Harris GS
 You are not authorized to post a reply. Forum Groups & Categories --Harris Geospatial Solutions ----Licensing & Installation ----General Questions Products --ENVI ----ENVI LiDAR ----ENVI ----ENVI SARscape ----ENVI OneButton --ENVI SARscape --IDL --Enterprise ----ENVI Services Engine (ESE) ----Jagwire ----ENVI for ArcGIS Services Editi...
MOST RECENT

### UAV Expo – A Growing Industry That’s Growing Up!

11/14/2017

This year’s UAV Expo had a strong agenda featuring a mix of sessions and speakers representing... more »

### What is a KMZ file?

11/13/2017

What is a KMZ file? A KMZ file is a placemark file used in Google Earth and Google Earth Pro. Since KMZ... more »