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
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 linear fit

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
ovince Posted - 08/01/2008 : 1:22:54 PM
Hi

I am trying to make 11 graphs in a loop and overplot their linear fit like:

%I="data";
for(i=1;i<=11;i++){
%A = "new$(i)";
create %A -w 10;

%(%A,1)=%(%I,1);
%(%A,2)=%(%I,i+1);

win -a %A;

wks.colSel(1);
wks.colSel(2);

//search "wks.colSel" for numbers like 200, 201 ...
worksheet -p 200 ORIGIN.OTP;

//fit linear
stat.data$ = %(%A,2);
stat.lr();
label -s -d 2500 700 -n myLabel1 "slope=$(stat.lr.b)"; //bold
label -s -d 2500 1000 -n myLabel2 "intercept=$(stat.lr.a)"; //bold
myLabel1.fsize = 36;
myLabel2.fsize = 36;
win -a "Graph$(i)"; //make active
run.section(lr.ogs,SimpleFit);
label -r Legend; //remove legend
}

Not sure why this does not work properly i.e. fit to the last graph is overplotted to all other graphs.


thanks
oliver
2   L A T E S T    R E P L I E S    (Newest First)
ovince Posted - 08/02/2008 : 03:06:43 AM
thanks for examples. Unfortunately I do not have version 8 of Origin :(
cpyang Posted - 08/01/2008 : 11:10:31 PM
the following code will work with active book with 1st sheet having data in XYYYY form, to fit col(1) as X and Y on all other columns.
This will work with Origin 8 SR2.


string mybk$=%H;
newsheet name:=FitLines c:=1;// add new sheet to hold fit lines
range aa = 1!;//1st sheet, assume we start with just one data sheet
range bb = FitLines!;// the newly added sheet called "FitLines"
bb.ncols = aa.ncols;//  Add new columns in FitLines sheet
// loop all cols and fit lr and put results into line
// the FitLR X-Function is used
dataset slopes, intercepts; // to hold fitting result parameters
slopes.SetSize(aa.ncols-1); // number of Ys in our data wks
intercepts.SetSize(slopes.GetSize());// not needed for now, but may be want this later
loop(ii,2,aa.ncols) {
	range dd = 1!(1,$(ii));
	fitlr i:=dd o:=FitLines!(1, wcol(ii));
	slopes[ii-1] = fitlr.b;//ii-1 because we loop from 2
	intercepts[ii-1] = fitlr.a;
}
// now we can make a plot with all the source data and fit and add a lable to show name and slope
loop(ii,2,aa.ncols) {
	range data = [mybk$]1!(1,wcol(ii));
	range fit = [mybk$]FitLines!(1,wcol(ii));
	win -t plot;
	plotxy data plot:=201 o:=<active>;//plot source data as scatter
	plotxy fit plot:=200 rescal:=0 color:=color(red) o:=<active>;
	label -r legend;// we dont really need a legend
label -s -q 2 -n myLabel1 "Linear Fit to %(1,@LM)
slope=$(slopes[ii-1])";
} 



I have added this example to

http://wiki.originlab.com/index.php?title=LabTalk:Curve_Fitting

and you can find more LabTalk examples there, using new Origin 8 syntax.

CP

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000