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 fir of multi XY

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
maric001 Posted - 10/24/2014 : 04:13:39 AM
Origin Ver. and Service Release (Select Help-->About Origin): 9.1 Sr3
Operating System: win 7 64bit

Hi there again!

Building a script for data analysis of multichannel data (Y) with reference channel(X). My sheet looks like X1Y1X2Y2Y2X3Y3X4Y4Y4......
The absolute channel nummer can vary and there are sometimes more than one Y for one X.

I need a linear fit of ech dataset. Using the GUI menu it is one click and it automatically fits each Y with its corresponding X.

How to do this as a labtalk script?

I tried some if-for combinations, but this is so far not working:

win -o IK {
loop(ss, 1, page.nlayers){
page.active=$(ss); //loop over all sheets
c=1; //internal counter for dataoutput
loop(ii, 2, wks.ncols){ //Search for X-columns
wks.col=ii;
if(wks.col.type==4){
wks.col=ii+1;
for(jj=ii+1;(jj<=wks.ncols&&wks.col.type==1);jj++){ //only select following Y-columns (this is not working so far)
fitLR iy:=($(ii),$(jj)) a:=[IKResults]1!(2)[$(c)] b:=[IKResults]1!(1)[$(c)]
c++;
}}}}}; //output of slope and intersect to resultssheet and counter +1

Thanks in advance!
5   L A T E S T    R E P L I E S    (Newest First)
PLayboaters Posted - 11/28/2014 : 08:43:49 AM
Hei,
thank you very much, this script works perfectly!
Best
Jonathan
lkb0221 Posted - 11/24/2014 : 10:20:43 AM
You can setup two loose datasets to store the median and slope during the looping, and then place them into two columns after that.

int Count = 1;
dataset dsSlope, dsMedian;
for (int TargetCol = 2; TargetCol <= wks.ncols; TargetCol = TargetCol + 2) {
double Slope;
fitLR iy:=$(TargetCol) b:=Slope;
dsSlope[$(Count)] = Slope;
dsMedian[$(Count)] = Median(wcol(TargetCol - 1));
Count++;
}

newsheet name:="Result" Labels:="Median|Slope";
col(1) = dsMedian;
col(2) = dsSlope;
PLayboaters Posted - 11/20/2014 : 12:30:05 PM
Hi
I had same problem (XYXYXYXYXY....) and as I am not a Labtalk expert this really helped a lot. Thank you very much for this solution. I am using it like this:


c=1; //internal counter for dataoutput
loop(ii, 2, wks.ncols)
{ //Just look for Y columns
if(wks.col$(ii).type==1)
{
fitLR iy:=(<auto>,$(ii))
b:=Slope1!1[$(c)];
c++;
}
}

Is there any possibility to get the median of each X Colum and change the ouput in a way that I get a dataset XY with X= Median and Y=Slope.
Would be great if anybody could help me.
Best
Jonathan


maric001 Posted - 10/28/2014 : 05:29:55 AM
Thanks Greg, works great!!
greg Posted - 10/24/2014 : 2:01:43 PM
Since you are using Plot Designators on your columns, you only need to look for Y columns and let Origin find the X. Also, there is a logic flaw with the location of your initial c variable:

win -o IK
{
c=1; //internal counter for dataoutput
loop(ss, 1, page.nlayers)
{
page.active=$(ss); //loop over all sheets
loop(ii, 2, wks.ncols)
{ //Just look for Y columns
if(wks.col$(ii).type==1)
{
fitLR iy:=(<auto>,$(ii))
a:=[IKResults]1!2[$(c)]
b:=[IKResults]1!1[$(c)];
c++;
}
}
}
}

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