The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Fitting data read
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

kdsaransh

India
89 Posts

Posted - 12/24/2014 :  10:05:24 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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

jasonzhao

China
262 Posts

Posted - 12/24/2014 :  11:52:44 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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

Edited by - jasonzhao on 12/25/2014 12:06:24 AM
Go to Top of Page

kdsaransh

India
89 Posts

Posted - 12/25/2014 :  06:18:40 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

jasonzhao

China
262 Posts

Posted - 12/29/2014 :  02:45:21 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

kdsaransh

India
89 Posts

Posted - 01/18/2015 :  10:23:36 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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.....
Go to Top of Page

jasonzhao

China
262 Posts

Posted - 01/19/2015 :  04:58:01 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

kdsaransh

India
89 Posts

Posted - 01/19/2015 :  05:16:30 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

jasonzhao

China
262 Posts

Posted - 01/19/2015 :  10:28:45 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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

Edited by - jasonzhao on 01/19/2015 10:30:21 PM
Go to Top of Page

tingqueji

Afghanistan
3 Posts

Posted - 01/21/2015 :  02:32:10 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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.
Go to Top of Page

kdsaransh

India
89 Posts

Posted - 01/22/2015 :  01:04:14 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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,
Go to Top of Page

jasonzhao

China
262 Posts

Posted - 01/22/2015 :  03:59:54 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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

Edited by - jasonzhao on 01/22/2015 04:02:45 AM
Go to Top of Page

kdsaransh

India
89 Posts

Posted - 01/23/2015 :  11:43:55 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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();
Go to Top of Page

jasonzhao

China
262 Posts

Posted - 01/26/2015 :  01:41:07 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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

Edited by - jasonzhao on 01/26/2015 01:42:37 AM
Go to Top of Page

kdsaransh

India
89 Posts

Posted - 01/28/2015 :  02:50:51 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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

Go to Top of Page

jasonzhao

China
262 Posts

Posted - 01/29/2015 :  02:49:18 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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


Go to Top of Page

kdsaransh

India
89 Posts

Posted - 01/29/2015 :  03:09:02 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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,
Go to Top of Page

jasonzhao

China
262 Posts

Posted - 01/29/2015 :  9:39:53 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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

Edited by - jasonzhao on 01/29/2015 9:40:38 PM
Go to Top of Page

HaroldSchaaf

USA
1 Posts

Posted - 02/10/2015 :  10:23:28 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
script from Jason is work

Harold
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000