custom batch fitting function

xthought
Posts: 3
Joined: 2017-04-19
Location: United States

Hi,

Can I get some assistance with writing some code. I explored the Batch Curve Fitting package and I played with the code on page III-232 of the Curve Fitting section. Batch Curve Fitting comes close but I don't believe I can alter the fitting range in an automated fashion. I NEED to write Igor code (a function ideally) that will i) fit a selected wave using my user-defined fitting function ii) repeat the fitting for different range as defined by cursors A & B (on 2 points per in the wave) iii) after each fit I need to make a graph of the wave, the fitting function, and an annotation of the graph with a textbox containing the fit results and iv) have all the fits results pushed into result history table. Also, instead of selecting waves in item i) I would be happy to iterate through waves that are items in a list using StringFromList(i, "1stfunctofit;2ndfunctofit;3rdfunctofit") since I don't have a crazy number of waves to fit... I just have a crazy number of points per wave. For example, I will need to run about 50 fits for each wave.

Big Thanks,
xthought


olelytken
Posts: 66
Joined: 2015-10-12
Location: Germany

You have to split the problem up into parts. Do you know how to create and call a function? Do you know how to create a string list and use the names in the list to declare waves? Do you know how to make a loop in a function? Do you know how to use FuncFit? Do you know how to use a user-defined fitting function? Do you know how to read out the positions of the cursors? Once you know which of those parts you have a problem with it will be easier for us to help you.


xthought
Posts: 3
Joined: 2017-04-19
Location: United States

Hi,

A while ago I wrote (above) to the forum for help and did not receive it. I amsurprised because I thought the goal of the forum was to. In the intervening time I worked on some simple code to run many fits of data. The fitting range can be varied (by looping). Each fit is printed to a graph along with the data. I am using FuncFit. To do this, I found some related code and did some alterations. Can someone advise me on a nice, easy way to write the fit parameter results to a table (of wave)s. Ultimately, I want to be able to plot these parameters. I am thinking that a first step toward this could be to create that table. Big Thanks

Function FitMagOrderParameter (mm)
Variable mm
Variable nn, aa,ii,ss

Wave MagY, MagX

aa=0
nn=0
//Make/O/N = (61)kd_global

do
Display MagY[nn,557] vs MagX[nn,557]
ModifyGraph mode=3, marker=41
label bottom "(Temperature)"
label left "(Magnetic Order Parameter)"

Make/D/O/N=4 W_coef
W_coef= {100,60,0.125, 0.01}

FuncFit/H="10"/NTHR=0/Q/TBOX=64 MOP_Fit W_coef MagY[nn+4,556] /X=MagX[nn+4,556]/D
wave w= fit_MagY
duplicate/o w $("fit"+num2istr(aa)+"_"+"MagY")
wave w1=$("fit"+num2istr(aa)+"_"+"MagY")
appendToGraph w1
ModifyGraph rgb($("fit"+num2istr(aa)+"_"+"MagY"))=(0,0,0)
// ModifyGraph marker($("fit"+num2istr(aa)+"_"+"MagY"))=41
Legend/C/N=text0/A=MC
removeFromGraph/z $nameofwave(w)

nn+=12 //Change This
aa+=1
while (nn < mm)

End

Function MOP_Fit(w,xx)
Wave w
Variable xx

Variable Ampl= w[0]
Variable T_N= w[1]
Variable half_exp= w[2]
Variable bkgd= w[3]

return w[0]*(1-(xx/w[1]))^(2*w[2]) + w[3]
End


HJDrescher
Posts: 331
Joined: 2015-01-20
Location: Germany

No offense, but I think that Ole's questions were rather appropriate.

We, the volunteers, really like to help others. However, we often need additional information on the user's problem. Especially for new members in the forum, we simply do not know the users skills in 'Menu Igor', Igor syntax and general programming. Hence, we like to ask such things. Once we get our questions answered, we are certainly happy to continue helping with higher precision.

HJ

PS: Please enclose code in <igor>...</igor> tags.


[ last edited October 10, 2017 - 10:24 ]
jjweimer
jjweimer's picture
Posts: 1288
Joined: 2007-08-14
Location: United States

xthought wrote:
Can someone advise me on a nice, easy way to write the fit parameter results to a table (of wave)s.

The results appear in W_coef and W_sigma. One possible method is to concatenate within your loop and then redimension the waves to Nx4 matrices.

make/D/O fitcoef=0, fitsigma=0
// start loop
...
concatenate W_coeff, fitcoeff
concatenate W_sigma, fitsigma
...
// end loop
...
-- > redimension fitcoeff and fitsigma as matrices

BTW, you DID receive help to your original question. You ignored it for six months, and then disrespected it in your follow up. The goal of this forum is user-to-user support and collaboration. The goal is not "tell me how to get some complex code running NOW because I NEED it".

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH


xthought
Posts: 3
Joined: 2017-04-19
Location: United States

Ok... concatenation with a loop. Thanks
I will not dirty up the forum with a response to your inaccurate assumptions about how I mentally process messages.
You have no way of knowing how I spend my time.


Back to top