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
 Grouping data in intervals
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Force

Denmark
9 Posts

Posted - 08/26/2014 :  07:56:20 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): origin 9.1pro
Operating System: win7

Hi,
I am still relative new with Origin LabTalk but I have a question that I hope someone can help me with.
I am looking for at way to reduce my data by grouping them in intervals/bins (x-values) and calculate the sum of the corresponding y-values within each bin. I have tried:

wsort bycol:=10 c1:=10 c2:=14; // Sort col10 to col14
reducexy [%A]%B!(col(10),col(11)) subgroup:=inc xincr:=10 xstats:=last ystats:=ave oy:=(<autoX>,<new>);
However, I need ystats:=ave to be ystats:=sum, but apparently the sum it is not supported by this function. How do I solve this problem?

Best regards,
Franz

greg

USA
1378 Posts

Posted - 08/27/2014 :  12:56:17 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
This will be supported in Origin 2015 - scheduled for release later this year.
Until then, you can use this script (after your sort):
// BEGIN SCRIPT
// Setup ranges
range ra1 = 10, ra2 = 11; // your X,Y columns
wks.addcol(LastX); // To receive groupX
range ra3 = $(wks.ncols);
wks.addcol(SumY); // To receive groupY
range ra4 = $(wks.ncols);
// Initialize
xincr = 10;
xstart = ra1[1];
rowstart = 1;
row = 1;
// Now loop
loop(ii,2,ra1.GetSize())
{
xval = ra1[ii];
if(xval >= xstart + xincr)
{
// Summarize
stats ra2[rowstart:ii-1];
ra3[row] = ra1[ii-1]; // Last X, not the same as
// ra3[row] = xstart + xincr; // Last possible X
ra4[row] = stats.sum;
row++;
xstart = xstart + xincr;
rowstart = ii;
}
}
// Final group
stats ra2[rowstart:ii-1];
ra3[row] = ra1[ii-1];
// ra3[row] = xstart + xincr;
ra4[row] = stats.sum;
//END SCRIPT
Go to Top of Page

Force

Denmark
9 Posts

Posted - 08/28/2014 :  05:23:10 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Greg

Your script works perfect. Thanks. However, if I include an extra Y column I end up with two new identical Y columns. Do I define my range wrong?



wsort bycol:=7 c1:=7 c2:=9;

range ra1 = 7, ra2 = 8, ra3 = 9; // your X,Y columns
wks.addcol(10); // To receive groupX;
range ra4 = $(wks.ncols);
wks.addcol(11); // To receive groupY
range ra5 = $(wks.ncols);
wks.addcol(12); // To receive groupY
range ra6 = $(wks.ncols);
// Initialize
xincr = 10;
xstart = ra1[1];
rowstart = 1;
row = 1;

loop(ii,2,ra1.GetSize())
{
xval = ra1[ii];
if(xval>= xstart + xincr)
{
// Summarize
stats ra2[rowstart:ii-1];
stats ra3[rowstart:ii-1];
ra4[row] = xstart + xincr;
ra5[row] = stats.sum;
ra6[row] = stats.sum;
row++;
xstart = xstart + xincr;
rowstart = ii;

}}

// Final group
stats ra2[rowstart:ii-1];
ra4[row] = ra1[ii-1];
ra5[row] = stats.sum;

stats ra3[rowstart:ii-1];
ra4[row] = ra1[ii-1];
ra6[row] = stats.sum;
}
Go to Top of Page

greg

USA
1378 Posts

Posted - 08/28/2014 :  09:55:55 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The stats tree is re-populated after each use of the stats X-Function. If you are doing stats on multiple datasets, you have to use your stats.property before your next use of stats.

Re-arrange some code:

wsort bycol:=7 c1:=7 c2:=9;

range ra1 = 7, ra2 = 8, ra3 = 9; // your X,Y columns
wks.addcol(10); // To receive groupX;
range ra4 = $(wks.ncols);
wks.addcol(11); // To receive groupY
range ra5 = $(wks.ncols);
wks.addcol(12); // To receive groupY
range ra6 = $(wks.ncols);
// Initialize
xincr = 10;
xstart = ra1[1];
rowstart = 1;
row = 1;

loop(ii,2,ra1.GetSize())
{
xval = ra1[ii];
if(xval>= xstart + xincr)
{
// Summarize
ra4[row] = xstart + xincr;
stats ra2[rowstart:ii-1];
ra5[row] = stats.sum;
stats ra3[rowstart:ii-1];
ra6[row] = stats.sum;
row++;
xstart = xstart + xincr;
rowstart = ii;
}
}
// Final group
ra4[row] = ra1[ii-1];
stats ra2[rowstart:ii-1];
ra5[row] = stats.sum;
stats ra3[rowstart:ii-1];
ra6[row] = stats.sum;
Go to Top of Page

Force

Denmark
9 Posts

Posted - 08/28/2014 :  4:00:33 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks Greg,

It now works perfectly.
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