Displaying FuncFit in a loop
isakova
All I want is to get a batch of graphs where a single subrange of data and a fit for it whould be on a one separate graph. Can you please help me? Here is my code:
Function myFit(w,x)
Wave w
Variable x
Variable bm= w[0]
Variable kd= w[1]
return w[0]*x/ (w[1]+x)
End
Function Ex (m)
Variable m
Variable n, a,i,s
a=0
n=0
Make/O/N = (61)kd_global
do
Display DNAbound_Protein[n,n+11] vs DNAfree[n,n+11]
ModifyGraph mode=3, marker=19
SetAxis left 0,1.2
SetAxis bottom 0, 35000
label bottom "(DNAfree)"
label left "(DNAbound/Protein)"
Make/D/O/N=2 W_coef
W_coef= {1.2,1}
FuncFit/H="10"/NTHR=0/Q/TBOX=64 myFit W_coef DNAbound_Protein[n,n+11] /X=DNAfree[n,n+11]/D
kd_global[a]= (W_coef[1]+477.1)/37.379
n+=12
a+=1
while (n < m)
Display kd_global
AppendToTable /W=Table0 kd_global
End
Wave w
Variable x
Variable bm= w[0]
Variable kd= w[1]
return w[0]*x/ (w[1]+x)
End
Function Ex (m)
Variable m
Variable n, a,i,s
a=0
n=0
Make/O/N = (61)kd_global
do
Display DNAbound_Protein[n,n+11] vs DNAfree[n,n+11]
ModifyGraph mode=3, marker=19
SetAxis left 0,1.2
SetAxis bottom 0, 35000
label bottom "(DNAfree)"
label left "(DNAbound/Protein)"
Make/D/O/N=2 W_coef
W_coef= {1.2,1}
FuncFit/H="10"/NTHR=0/Q/TBOX=64 myFit W_coef DNAbound_Protein[n,n+11] /X=DNAfree[n,n+11]/D
kd_global[a]= (W_coef[1]+477.1)/37.379
n+=12
a+=1
while (n < m)
Display kd_global
AppendToTable /W=Table0 kd_global
End
Just write after the funcfit command:
duplicate/o fit_DNAbound_Protein, $("fit"+num2istr(a)+"_"+"DNAbound_Protein")
And if you want to display the fits together with your data add the following:
wave w=$("fit"+num2istr(a)+"_"+"DNAbound_Protein")
setaxis bottom, leftx(w),rightx(w)-deltax(w)
Andreas
June 2, 2010 at 05:14 am - Permalink
This is indicated by the parameter /D at the end of FuncFit (look into the help of 'CurveFit') which just writes the result in a wave named 'fit_' + inputname. Since the Wave you are fitting has the same name (only the subrange is different) the result has the same name, too. I think to solve your problem you can just try to define a new output name with /D='newname' (e.g.
"FitResult"+num2str(n)
) every iteration, so you don't even have to duplicate waves.June 2, 2010 at 05:25 am - Permalink
It has the possible advantage that you can do each of your fits using the same destination wave. You could write:
do
...
FuncFit ... DNAbound_Protein[n,n+11] /X=DNAfree[n,n+11]/D= DNAbound_Protein_Fit[n,n+11]
...
while ...
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
June 2, 2010 at 11:20 am - Permalink
June 3, 2010 at 02:42 am - Permalink
Everything seem to be correct and makes sense. But still does not work properly. Mainly the plotting part.
when I'm trying to add lines
wave w=$("fit"+num2istr(a)+"_"+"DNAbound_Protein")
setaxis bottom, leftx(w),rightx(w)-deltax(w)
as chozo suggested, it displays the right fit but with the another fit (fit_DNAbound_Protein). and then I've tried to modify it on:
it displays the fit_num2str(a) properly but puts all the the data points (DNAbound_Protein[n,n+11]) at x=0 and not as it should be at x=DNAfree[n,n+11].
Can I modify it somehow to work properly?
Thank you,
Alina.
June 3, 2010 at 05:44 am - Permalink
The problem is probably related to the SetAxis commands. Unfortunaltey I don't know how your data look like, so I can't test it, but please give the following a try:
Variable m
Variable n, a,i,s
a=0
n=0
Make/O/N = (61)kd_global
do
Display DNAbound_Protein[n,n+11] vs DNAfree[n,n+11]
ModifyGraph mode=3, marker=19
// SetAxis left 0,1.2
// SetAxis bottom 0, 35000
label bottom "(DNAfree)"
label left "(DNAbound/Protein)"
Make/D/O/N=2 W_coef
W_coef= {1.2,1}
FuncFit/H="10"/NTHR=0/Q/TBOX=64 myFit W_coef DNAbound_Protein[n,n+11] /X=DNAfree[n,n+11]/D
wave w= fit_DNAbound_Protein
duplicate/o w $("fit"+num2istr(a)+"_"+"DNAbound_Protein")
wave w1=$("fit"+num2istr(a)+"_"+"DNAbound_Protein")
appendToGraph w1
removeFromGraph/z $nameofwave(w)
kd_global[a]= (W_coef[1]+477.1)/37.379
n+=12
a+=1
while (n < m)
Display kd_global
AppendToTable /W=Table0 kd_global
End
As I do not know what the reason is for the original SetAxis commands, I commentized them. You can reactivate them if you know what you're doing.
I hope this helps,
Andreas
June 10, 2010 at 12:09 am - Permalink
Your corrected code works just perfect!
Even uncommented SetAxis does not change the correctness of the plots.
Thank you.
Alina
June 9, 2010 at 02:26 am - Permalink