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
 Linear fir of multi XY
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

maric001

Germany
5 Posts

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

greg

USA
1378 Posts

Posted - 10/24/2014 :  2:01:43 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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++;
}
}
}
}
Go to Top of Page

maric001

Germany
5 Posts

Posted - 10/28/2014 :  05:29:55 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks Greg, works great!!
Go to Top of Page

PLayboaters

3 Posts

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



Edited by - PLayboaters on 11/20/2014 12:31:00 PM
Go to Top of Page

lkb0221

China
497 Posts

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

Edited by - lkb0221 on 11/24/2014 10:22:15 AM
Go to Top of Page

PLayboaters

3 Posts

Posted - 11/28/2014 :  08:43:49 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hei,
thank you very much, this script works perfectly!
Best
Jonathan
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