How to insert variable into Hold function in FuncFit
shankar.dutt
Hi everyone,
I am new to Igor and I am trying to build a program in which the function holds or not hold a value during fitting based on some other function. As you can see in the code, I want to use h1 h2.. h5 values, but I am not sure how to implement this. Please help.
Thanks
NVAR HC_amp,HC_Rc,HC_pol,HC_Rough,HC_Back
NVAR h1, h2, h3, h4, h5
Make/D/O root:HC_coeff = {HC_amp,HC_Rc,HC_pol,HC_Rough,HC_Back}
FuncFit/W=1/TBOX=512/G/N=0/H="h1 h2 h3 h4 h5" HC_Fit_Func, root:HC_coeff, root:waveI(xcsr(A),xcsr(B)) /X=root:waveq /D
Wave HC_coeff
print root:HC_coeff
Wave W_sigma
print W_sigma
SetActiveSubwindow Panel0#G0
AppendtoGraph/W=#/C=(1,9611,39321) root:fit_waveI vs root:waveq
ModifyGraph lsize(fit_waveI)=2
NVAR h1, h2, h3, h4, h5
Make/D/O root:HC_coeff = {HC_amp,HC_Rc,HC_pol,HC_Rough,HC_Back}
FuncFit/W=1/TBOX=512/G/N=0/H="h1 h2 h3 h4 h5" HC_Fit_Func, root:HC_coeff, root:waveI(xcsr(A),xcsr(B)) /X=root:waveq /D
Wave HC_coeff
print root:HC_coeff
Wave W_sigma
print W_sigma
SetActiveSubwindow Panel0#G0
AppendtoGraph/W=#/C=(1,9611,39321) root:fit_waveI vs root:waveq
ModifyGraph lsize(fit_waveI)=2
The /H string must consist of 0 or 1 characters only. For example for a line fit, with parameters a and b in that order, /H="10" holds a and allows b to vary.
April 17, 2019 at 07:36 pm - Permalink
You might construct a hold string like this:
String hstring = ""
hstring += SelectString(doH1, "0", "1")
hstring += SelectString(doH2, "0", "1")
hstring += SelectString(doH3, "0", "1")
hstring += SelectString(doH4, "0", "1")
hstring += SelectString(doH5, "0", "1")
return hstring
end
And in the function that calls FuncFit:
FuncFit/W=1/TBOX=512/G/N=0/H=holds HC_Fit_Func, root:HC_coeff, root:waveI(xcsr(A),xcsr(B)) /X=root:waveq /D
There may be a better way for you to represent the holds, such as elements of a 5-point wave. Using a wave you could write a loop instead of all those separate lines with "hstring += ..."
April 18, 2019 at 11:21 am - Permalink