T O P I C R E V I E W |
kdsaransh |
Posted - 12/24/2014 : 10:05:24 AM Hello,
I have a small problem.
After linear fitting a graph, we get intercept and slope on the graph. How can i get the intercept and the slope value in a sheet using the script. In other words , how to read the fitting data to a new sheet.
Thanks a lot.
Regards, Rajesh Agarwal
|
17 L A T E S T R E P L I E S (Newest First) |
HaroldSchaaf |
Posted - 02/10/2015 : 10:23:28 PM script from Jason is work
Harold
|
jasonzhao |
Posted - 01/29/2015 : 9:39:53 PM Hello,
Once you change the ROI, you can run the command again:
gg.output();
Please set the output to Worksheet as graph shown above. and you can refer to this page for further informations http://www.originlab.com/doc/LabTalk/ref/Gadget-obj
Best regards! Jason OriginLab Technical Service
|
kdsaransh |
Posted - 01/29/2015 : 03:09:02 AM Wow great. I didn't knew that it could be done in this way.
But, is there a way to do using script. I mean to say that if I manually change the ROI region then the slope and intercept gets automatically updated using script.
Again lots of thanks. You are doing a great job helping us out.
regards,
|
jasonzhao |
Posted - 01/29/2015 : 02:49:18 AM Hello,
Please see the graph below:
Click Preference in list to open the preference dialog, select 'worksheet' as the Output to. click OK to apply. Then, Select new optput in the list to get a new output sheet, once you change the ROI sze, please 'Update the Last Output'
Best regards, Jason Zhao OriginLab Tech Service
|
kdsaransh |
Posted - 01/28/2015 : 02:50:51 AM Hello, Great.
But i have a small problem. i have to change the ROI region manually so that i have a perfect fitting and hence the slope and intercept values also changes which is shown in the graph,but they do not automatically gets updated in the sheet.
StartRange=70; EndRange=950000; mks1=xindex(StartRange,%C); mks2=xindex(EndRange,%C);
// from quick fit gadget, using fix ROI addtool_quickfit trroi.XScale.leftx:=70 trroi.XScale.rightx:=100000 trroi.XScale.fixscale:=1 trroi.ShowTop.RSqr:=1 trroi.RectColor:=17 trtable.Params:=2 trtable.ReduChisq:=0 trtable.Correlation:=0 trreport.ReduChisq:=0 trreport.Correlation:=0;
gadget gg = rect; //declare LT gadget variable gg.output();
range p1=1!1; //The first plot set %c -c 4; //Change the line's color set %c -d 1; //Change the line's style.
tree mytr; //define a tree variable gg.getresult(mytr); //output result to the tree variable mytr
window -a book2; newsheet name:=result$(ii-1);
col(A)[1]=mytr.Intercept; //pass the value in results to worksheet col(B)[1]=mytr.Slope; } newbook name:="Transit time" sheet:=1; for(int ii = 2; ii<=n+1; ii++) { wrcopy iw:=[book2]result$(ii-1)! ow:=[Transit time]sheet1! r1:=1 dr1:=$(ii-1) dc1:=4; }
Thanks
|
jasonzhao |
Posted - 01/26/2015 : 01:41:07 AM Hello,
You Script is modified in this way, a new sheet is created for saving results.
StartRange=70;
EndRange=950000;
mks1=xindex(StartRange,%C);
mks2=xindex(EndRange,%C);
addtool_quickfit trroi.XScale.leftx:=70 trroi.XScale.rightx:=100000 trroi.XScale.fixscale:=1 trroi.ShowTop.RSqr:=1 trroi.RectColor:=17 trtable.Params:=2 trtable.ReduChisq:=0 trtable.Correlation:=0 trreport.ReduChisq:=0 trreport.Correlation:=0;
gadget gg = rect; //declare LT gadget variable
gg.output();
tree mytr; //define a tree variable
gg.getresult(mytr); //output result to the tree variable mytr
window -a book1;
newsheet name:=result;
col(A)[1]=mytr.Intercept; //pass the value in results to worksheet
col(B)[1]=mytr.Slope;
Best regards, Jason Zhao OriginLab Tech Service |
kdsaransh |
Posted - 01/23/2015 : 11:43:55 AM Hello again,
Thank you for the generous help.
I am using the below quit fit code coz my x value is not fixed and i have to change the ROI to get the correct slope and intercept value. How can i read the slope and intercept value to a new worksheet using the quick fit gadget.
StartRange=70; EndRange=950000; mks1=xindex(StartRange,%C); mks2=xindex(EndRange,%C);
// from quick fit gadget, using fix ROI addtool_quickfit trroi.XScale.leftx:=70 trroi.XScale.rightx:=100000 trroi.XScale.fixscale:=1 trroi.ShowTop.RSqr:=1 trroi.RectColor:=17 trtable.Params:=2 trtable.ReduChisq:=0 trtable.Correlation:=0 trreport.ReduChisq:=0 trreport.Correlation:=0;
gadget gg = rect; //declare LT gadget variable gg.output();
|
jasonzhao |
Posted - 01/22/2015 : 03:59:54 AM Hello,
Please download the attached file, which helps show all the fitted lines, you can drag and drop the x-function,setplotuid.oxf, in Origin: http://www.originlab.com/ftp/forum_and_kbase/Images/setplotuid.zip
Then, run the following codes below:
// GUI tree for linear fit
tree lrGUI;
// initialize the GUI tree, with the FitLinear clas
xop execute:=init classname:=FitLinear iotrgui:=lrGUI;
//Specify all data plots on graph to be input data in the GUI tree
ii = 1;
doc -e d
{
%A = xof(%C);
lrGUI.GUI.InputData.Range$(ii).X$ = %A;
lrGUI.GUI.InputData.Range$(ii).Y$ = %C;
setplotuid lrGUI ii; //set plot id to lrgui. please comment this line if you don't have setplotuid.oxf
ii = ii + 1;
}
lrGUI.GUI.Fit.ApparentFit = 1;
// perform linear fit and generate a report with the prepared GUI tree;
xop execute:=run iotrgui:=lrGUI otrresult:=lrOut;
xop execute:=report iotrgui:=lrGUI;
// clean up linear fit operation objects after fitting
xop execute:=cleanup;
window -a book1;
newsheet name:=result;
col(A)[1]=lrOut.Summary.R1.Intercept_Value;
col(B)[1]=lrOut.Summary.R1.Slope_Value;
col(A)[2]=lrOut.Summary.R2.Intercept_Value;
col(B)[2]=lrOut.Summary.R2.Slope_Value;
Best regards, Jason Zhao OriginLab Tech Service |
kdsaransh |
Posted - 01/22/2015 : 01:04:14 AM Hi Thanks a lot,
This code give me the slope and intercept value in a worksheet for all the plots in the graphs, but it shows fitted line for a single graph only.
regards, |
tingqueji |
Posted - 01/21/2015 : 02:32:10 AM Actually my graph is on log-log scale, hence i want to apparent linear fit the graph with the slope and intercept value : 1. on the graph itself 2. On a separate sheet 3. along with the fitted line to show to my supervisor. 4. I also want to change the properties of the fitted line like color, width , short dash etc.
|
jasonzhao |
Posted - 01/19/2015 : 10:28:45 PM Hello,
You can use doc -e d to specify the multiple columns name: and refer to http://www.originlab.com/doc/LabTalk/ref/Document-cmd#-e_object_.7Bscript.7D.3B_Execute_the_given_script_for_all_objects for details about doc command
// GUI tree for linear fit
tree lrGUI;
// initialize the GUI tree, with the FitLinear clas
xop execute:=init classname:=FitLinear iotrgui:=lrGUI;
//Specify all data plots on graph to be input data in the GUI tree
ii = 1;
doc -e d
{
lrGUI.GUI.InputData.Range$(ii).Y$ = %C;
ii = ii + 1;
}
lrGUI.GUI.Fit.ApparentFit = 1;
// perform linear fit and generate a report with the prepared GUI tree
xop execute:=report iotrgui:=lrGUI;
// clean up linear fit operation objects after fitting
xop execute:=cleanup;
window -a book1;
newsheet name:=result;
col(A)[1]=lrOut.Summary.R1.Intercept_Value;
col(B)[1]=lrOut.Summary.R1.Slope_Value;
col(A)[2]=lrOut.Summary.R2.Intercept_Value;
col(B)[2]=lrOut.Summary.R2.Slope_Value;
col(A)[3]=lrOut.Summary.R3.Intercept_Value;
col(B)[3]=lrOut.Summary.R3.Slope_Value;
Best regards, Jason Zhao OriginLab Tech Service |
kdsaransh |
Posted - 01/19/2015 : 05:16:30 AM Hi,
My single worksheet has XYYY data. So when i plot this, a get 3 graphs. Now when i use the given script, it fits only one graph and gives the corresponding slope and intercept in result sheet. But how do i fit all the three graphs and get their slope and intercept in the result sheet.
I hope the problem is clear. It seems very trivial after you had given the code, But still i am not able to do so.
Thanks |
jasonzhao |
Posted - 01/19/2015 : 04:58:01 AM Hello,
Would you please illustrate the structure of your worksheet? Does all data in only one sheet, or in multiple sheets. and does all Y columns share the same X colume with XYYY or XYXY.
In addition, you can refer to this tpoic http://www.originlab.com/forum/topic.asp?TOPIC_ID=19577 in which XOP is used to solve the linear fit on graph.
Best regards, Jason Zhao OriginLab Tech Service
|
kdsaransh |
Posted - 01/18/2015 : 10:23:36 AM Hi there,
Thanks a lot for your help. But now i am stuck with another problem.
My graph has a single layer, but has multiple graphs. The scripts works fine with one graphs and gives the slope and intercept of only the active graph , but not for the other graphs. How can i modify the script so that it gives me the slope and intercept of all the three graphs on the sheet.
Thanks in advance..... |
jasonzhao |
Posted - 12/29/2014 : 02:45:21 AM Hello,
You can use the XOP commend to conduct the apparent fit, and refer to page below: http://www.originlab.com/doc/LabTalk/examples/Curve-Fitting#Apparent_Linear_Fit_with_xop_X-Function_and_Get_Result_Tree;
Here is the example of the apparent fit on an active graph,
tree lrGUI;
xop execute:=init classname:=FitLinear iotrgui:=lrGUI;
lrGUI.GUI.Fit.ApparentFit = 1;
xop execute:=run iotrgui:=lrGUI otrresult:=lrOut;
xop execute:=report iotrgui:=lrGUI;
xop execute:=cleanup;
window -a book1;
newsheet name:=result;
col(A)[1]=lrOut.Summary.R1.Intercept_Value;
col(B)[1]=lrOut.Summary.R1.Slope_Value;
for the graph format, please refer to this page: http://www.originlab.com/doc/LabTalk/guide/Formatting-Graphs
Best regards, Jason Zhao OriginLab Tech Service
|
kdsaransh |
Posted - 12/25/2014 : 06:18:40 AM Thanks for the reply.
This solves my problem to some extent.
Actually my graph is on log-log scale, hence i want to apparent linear fit the graph with the slope and intercept value : 1. on the graph itself 2. On a separate sheet 3. along with the fitted line to show to my supervisor. 4. I also want to change the properties of the fitted line like color, width , short dash etc.
I have been struggling for fitting linearly the apparent graph.
Thanks
|
jasonzhao |
Posted - 12/24/2014 : 11:52:44 PM Hello,
Please try the script below: with workbook active:
fitLR iy:=(1,2) oy:=col(FitData);
// a tree object named fitLR is created, and contains the output values
fitLR.a = ; // output the fitted intercept
fitLR.b = ; // output the fitted slope;
col(Result)[1]=fitLR.a;
col(Result)[2]=fitLR.b;
or with the graph active:
fitLR iy:=<active> oy:=[Book1]Sheet1!Col(FitData);
// a tree object named fitLR is created, and contains the output values
fitLR.a = ; // output the fitted intercept
fitLR.b = ; // output the fitted slope;
window -a book1;
col(Result)[1]=fitLR.a;
col(Result)[2]=fitLR.b;
Best regards, Jason Zhao OriginLab Tech Service |