X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 21 Dec 2012 03:50 AM by  anon
mean
 2 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
21 Dec 2012 03:50 AM
    hello somebody know how calculate the mean but excluding some values? Example: vector[3,1,2,6,-1,4,3]. I want to calculate the mean but excluding the value -1 thanks

    Deleted User



    New Member


    Posts:
    New Member


    --
    21 Dec 2012 09:33 AM
    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

    Deleted User



    New Member


    Posts:
    New Member


    --
    05 Jan 2013 04:20 AM
    hello and many thanks complete and useful answer!!!
    You are not authorized to post a reply.