One way is to use the Where() function to find all values that are not -1. Try the following:
IDL> vector = [3,1,2,6,-1,4,3]
IDL> w = where(vector ne -1)
IDL> print, mean(vector[w])
3.16667
Or you can do it on one line like this:
IDL> print, mean(vector[where(vector ne -1)])
3.16667
One note though, in practice you should always check the result of Where() first to make sure that it found something. If the condition given to the where function (vector ne -1) finds no elements that meet that criteria, Where() will return a value of -1. So one way to check this in your program would be something like this:
vector = [3,1,2,6,-1,4,3]
w = where(vector ne -1)
if (w[0] eq -1) then begin
print, "your error message here"
endif else begin
m = mean(vector[w])
endelse
-Josh
Exelis VIS
|