[Thread Prev][Thread Next][Index]

[ferret_users] Remove the mean over an associated value



I have a variable (MYVAR) in which each value has an associated coordinate value (PHI). There are in general many values of MYVAR for each PHI.

At each PHI, I want to remove the phi-mean over the many values of MYVAR.

It is easy to find this mean using ZAXREPLACE:

(Let us say that MYVAR and PHI are on a z-axis; else simply use ZSEQUENCE to force them to be).

! sort for phi order, since ZAXREPLACE requires monotonic ordering:
let sortindz=sortk(PHI)
let sortphi=samplek(PHI,sortindz)
let sortvar=samplek(MYVAR,sortindz)

! find the phi-mean at chosen intervals
define axis/z=0:1:.01 zbin      ! PHI goes from 0 to 1
let varbin=zaxreplace_bin(sortvar,sortphi,z[gz=zbin])

This works great: VARBIN is the desired mean. Check this by plotting:

plot/vs/line MYVAR,PHI         ! many overlaid lines
plot/over/line=8 VARBIN      ! simple mean at each binned value of PHI

But my problem is: how to subtract VARBIN from MYVAR? (or SORTVAR?)
They are on different axes (note the plot/vs above).

What I want to do is:

For each value of MYVAR, find the value of VARBIN corresponding to its PHI, subtract.

I could probably do this in a repeat loop with writing out, but there are about 25000 values and I was hoping for a more elegant solution ....

Billy K



[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement