Curve Fitting with macro

Hi,
I would like to fit a lot of data with a polynomial function by using an igor macro.

In the macro, I write

CurveFit/NTHR=0/TBOX=0 poly $namespectre /M=$namemask
$nameBLref=poly(W_coef,x)

In this case, an error message appears "ambigous wave point number" and $namespectre is selected.

I also try this syntax :
CurveFit/NTHR=0/TBOX=0 poly 3 $namespectre /M=$namemask
$nameBLref=poly(W_coef,x)
Now, 3 is selected, and the error message is "expected operator"

From a general point of view, I have a problem with this function. How can I define the polynomial terms in macro ?
Should I create an user-defined function ?

Thank you a lot for your valued assistance
Hélène
Hi Hélène,

welcome to the forum. Your code is nicer to read if you use the igor tags.

I would say the igor error message wants to tell you that the string namespectre does not hold a valid wave.
It is generally easier if you use wave references instead of $ string magic.

Something like
Make/O data = p^2
Display data
CurveFit/TBOX=115 poly 3, data/D


works here.
You can use a numeric variable for the terms parameter. Here is a simple function that demonstrates that:
Function test(order)
    Variable order

    Wave junk
    CurveFit/M=2/W=0 poly (order+1), junk/D
end

The "+1" is because the input is number of terms, not order of the polynomial.

But perhaps you should check out the Batch Curve Fit package (Analysis->Packages->Batch Curve Fit). It is moderately complicated; you will want to look at the demo: File->Example Experiments->Curve Fitting->Batch Curve Fit Demo.pxp.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Hi
many thanks for your answers.
Now I fix the problem !

It is a judicious idea to define the order, John. Igor is the best, anyway !

Thanks a lot !

Hélène