How to insert variable into Hold function in FuncFit

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

 

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.

You might construct a hold string like this:

Function/S constructHoldString(Variable doH1, Variable doH2, Variable doH3, Variable doH4, Variable doH5)
    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:

String holds = constructHoldString(H1, H2, H3, H4, H5)
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 += ..."