CurveFit + mask wave with own destination wave

I have a problem with using CurveFit with both a mask wave specified and supplying my own destination wave (i.e., /D=destname). With just the /D flag everything works as I would expect it, namely the fit produces a wave fit_mydata with the full fit contained. But when I supply my own destination wave the resulting fit is not written within the masked range, i.e., the destination just keeps whatever data is in there. The question is why would one want that and why is this triggered by specifying a destination wave? If I would like to omit the result I could mask the result later myself. For now this unnecessarily complicates code, as I cannot just store the fit result in a free wave with my own name for simple processing. I have to draw up the custom wave with the name 'fit_XXX' and get rid of it manually. How can I get the result written just like with /D?

Compare:

Make/d/o/n=100 test, mask = 1, myresult = 0
test = gauss(x,50,10)
mask[40,60] = 0
CurveFit/Q gauss test /D /M=Mask
CurveFit/Q/L=(DimSize(test,0)) gauss test /D=myresult /M=Mask

Also have a look at the example experiment.

Masked CurveFit.pxp

In the example you give, omit the /D flag and add a line to assign the fit result to the output wave:

myresult=gauss1D(w_coef,x)

There's a lot of this type of thing in my baselines package, which is mostly a GUI for performing masked fits. For most of the built-in functions you have to type in the equation to make the wave assignment, but for Gauss fit there's the gauss1D function that works with the coef wave from CurveFit.

The behavior of /D=<your wave> with masked or subrange fits is intended to allow you to do consecutive fits on different subranges, keeping the results of both fits. You can pre-fill your destination wave with your choice of value. I usually assign NaN to the wave. I have toyed with the notion of adding a flag, something like /DFIL=<value>, but that's something you can do easily yourself, so it's not compelling, especially given the number of flags for the CurveFit and FuncFit operations that already exist.

Thanks Tony and John for the replies.

Yes, my use case is actually very similar to the baseline package and I am using a poly fit (the Gaussian was just for demonstration). I see that I can just use result = poly(coef,x) here and be done with it, just as suggested by Tony. So I guess the case is solved.

I see now that this behavior is intended, and I somewhat see the point. At first I thought I am missing a flag or this was even a bug. Maybe a small note either in the help for the /M or /D flags would avoid confusion? 

Forum

Support

Gallery

Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More