Accessing Fit Results in Script After Fitting
From OriginLab Wiki
This article describes how to modify After Fit scripts you may have used with fitting functions in versions 7.5 or earlier, so as to make them work in versions 8.0 and later.
 Getting Parameter Values in Version 8.0 and Later
In versions 8.0 and later, the NLSF object is no longer used, so after a fit is performed, fit results cannot be accessed from script using expressions such as NLSF.p1=;
Instead, one needs to get the fit results from the fit report sheet generated by Origin. This can be done by using the getnlr X-Function.
User has the following script that they added to the Script: After Fit edit box in the fitter dialog in version 7.5. The script computes some new quantities based on fit values, and adds a custom text label to the active graph:
var1=(0.5^(-(1/$(nlsf.P2)))-1)/$(nlsf.P3); var2=(0.25^(-1*(1/$(nlsf.P2)))-1)/$(nlsf.P3); var3=$(nlsf.cod); var4=(0.1^(-1*(1/$(nlsf.P2)))-1)/$(nlsf.P3); label -s -sa -n fitresults (P1 = $(nlsf.p1) Alpha = $(nlsf.p2) Beta = $(nlsf.p3) DT \-(50) = $(var1) DT \-(75) = $(var2)) DT \-(90) = $(var4)) R \+(2)=$(var3);
In 8.0 and later, the following steps can be used:
- Press F9 hot key to open the Function Organizer dialog.
- Select your fitting function, and on the right side scroll down to the Script After Fitting edit box
- Enter the following modified script, which uses the getnlr X-Function to first get all results to a tree variable:
// Get fit results into a tree variable getnlr tr:=myfit iw:=__Report$ showall:=0 pnotation:=1; // Now values can be accessed from tree var1=(0.5^(-(1/$(myfit.P2)))-1)/$(myfit.P3); var2=(0.25^(-1*(1/$(myfit.P2)))-1)/$(myfit.P3); var3=$(myfit.cod); var4=(0.1^(-1*(1/$(myfit.P2)))-1)/$(myfit.P3); label -s -sa -n fitresults (P1 = $(myfit.p1) Alpha = $(myfit.p2) Beta = $(myfit.p3) DT \-(50) = $(var1) DT \-(75) = $(var2)) DT \-(90) = $(var4)) R \+(2)=$(var3);
- Save the function and close Function Organizer
- Create a graph of your data (required for this example, as the code pastes a label to the graph)
- Perform fitting with the function. The After Fit script will be visible when you select the Code tab in the new fitter dialog
- After the fitter dialog is closed at the end of the fit, the script is then executed and the label gets added
 Derived Parameters
Origin version 8 and later provides a better way for user to define and compute Derived Parameters from the fitting function parameters. This mechanism can be used instead to compute the desired quantities, and the added benefit is that the specified derived parameters will be available in the Parameter table of the result sheet created by the new fitter dialog. For more information, please refer to the Origin help file.