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
 combine columns into a single column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

aliasthethird

USA
4 Posts

Posted - 03/28/2012 :  5:09:25 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,
Can this really be this difficult?
Im trying to combine n columns from a data sheet into a single column on a different sheet.
Here is my attempted. It works outside of the loop, but not inside. The loop is what I'm after.
Any ideas?
Thanks


//create data
range r1 = [Book1]Sheet1!wcol(1);
r1 = data(1,6);
for (ii=1; ii<=4; ii++)
{
range r2 = [Book1]Sheet1!wcol(ii);
r2=r1*ii;
}


//This loop is not working
range OriData = [Book1]Sheet1!;
int Start = 1;
int End = 0;
int ColN=OriData.ncols;
for (ii=1; ii<=ColN; ii++)
{
range r1 = [Book1]Sheet1!wcol(ii);
Start = ;
End = Start + r1.getsize()-1;
End=;
range r2 = [Book1]Sheet1!wcol(ColN+1)[Start:End];
r2 = r1;
Start = End+1;
}


//but this works
range r1 = [Book1]Sheet1!wcol(1);
range r2 = [Book1]Sheet1!wcol(ColN+2)[1:6];
r2 = r1;
range r1 = [Book1]Sheet1!wcol(2);
range r2 = [Book1]Sheet1!wcol(ColN+2)[7:12];
r2 = r1;
range r1 = [Book1]Sheet1!wcol(3);
range r2 = [Book1]Sheet1!wcol(ColN+2)[13:18];
r2 = r1;
range r1 = [Book1]Sheet1!wcol(4);
range r2 = [Book1]Sheet1!wcol(ColN+2)[19:24];
r2 = r1;

Kathy_Wang

China
159 Posts

Posted - 03/29/2012 :  04:04:35 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

The problem occurs because in range notation, the variable "end" is by default to indicate the last row of the column. So I suggest that instead of using "end" as the variable name, you could choose other variable names. For example, I modified your script as follow and only change "Start" into "i" and "End" into "j", this shall work fine.(Origin version 8.6 SR2)


//create data
range r1 = [Book1]Sheet1!wcol(1);
r1 = data(1,6);
for (ii=1; ii<=4; ii++)
{
range r2 = [Book1]Sheet1!wcol(ii);
r2=r1*ii;
}


//This loop is now working
range OriData = [Book1]Sheet1!;
int i = 1;
int j = 0;
int ColN=OriData.ncols;
for (ii=1; ii<=ColN; ii++)
{
range r1 = [Book1]Sheet1!wcol(ii);
i = ;
j = i + r1.getsize()-1;
j =;
range r2 = [Book1]Sheet1!wcol(ColN+1)[i:j];
r2 = r1;
i = j+1;
} 



Kathy
Originlab

Edited by - Kathy_Wang on 03/29/2012 04:11:38 AM
Go to Top of Page

aliasthethird

USA
4 Posts

Posted - 03/29/2012 :  09:06:08 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Its always the little things.
Thanks you so much.
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