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
 Splitting rows into multiple columns
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

j.miao

Germany
4 Posts

Posted - 07/24/2014 :  09:10:22 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hello everyone,

I have a data with two columns, i.e. column (1), column (2).

I want to separate the columns, meaning that Origin is supposed to copy the first 150 data points from columns (1, 2) to columns (3, 4), and the second 150 data points from columns (1, 2) to columns (5, 6), and so on

However, I have 1500 rows, or 10 columns with 150 data points each, so writing a script like that will take considerable time. (or even more rows)

So my question is: How can I write a kind of loop for that function which would also make it easy to change the number of points?

I use OriginPro 8.5.1.


Thanks in advance for any help!
07/24/2014

JUN

lkb0221

China
497 Posts

Posted - 07/24/2014 :  10:54:34 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

The following script will only copy numeric data over.
//
range r1 = 1; // Col(1)
range r2 = 2; // Col(2)
int Num = (wks.nrows / 150) + 1; // +1 for extra data
for (int ii = 1; ii <= Num; ii++)
{
range d1 = $(2*ii+1);
range d2 = $(2*ii+2);
copydata irng:=r1[$(ii*150-149):$(ii*150)] orng:=d1;
copydata irng:=r2[$(ii*150-149):$(ii*150)] orng:=d2;
}
//


Zheng
OriginLab

Edited by - lkb0221 on 07/24/2014 10:56:12 AM
Go to Top of Page

j.miao

Germany
4 Posts

Posted - 07/24/2014 :  11:19:32 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks a lots for your help. It works well and make a good shape.

However, the columns cannot be set to be X and Y, respectively.
meaning, col(3)-X ; col(4)-Y; col(5)-X ; col(6)-Y; col(7)-X ; col(8)-Y; and so on.

Could you give a suggestion or improve that script?

Thanks again!

quote:
Originally posted by lkb0221

Hi,

The following script will only copy numeric data over.
//
range r1 = 1; // Col(1)
range r2 = 2; // Col(2)
int Num = (wks.nrows / 150) + 1; // +1 for extra data
for (int ii = 1; ii <= Num; ii++)
{
range d1 = $(2*ii+1);
range d2 = $(2*ii+2);
copydata irng:=r1[$(ii*150-149):$(ii*150)] orng:=d1;
copydata irng:=r2[$(ii*150-149):$(ii*150)] orng:=d2;
}
//


Zheng
OriginLab



JUN
Go to Top of Page

j.miao

Germany
4 Posts

Posted - 07/24/2014 :  11:28:23 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Moreover,

If the interval was 200 (or 250) instead of 150, how could I do with that?

Thanks again!


quote:
Originally posted by lkb0221

Hi,

The following script will only copy numeric data over.
//
range r1 = 1; // Col(1)
range r2 = 2; // Col(2)
int Num = (wks.nrows / 150) + 1; // +1 for extra data
for (int ii = 1; ii <= Num; ii++)
{
range d1 = $(2*ii+1);
range d2 = $(2*ii+2);
copydata irng:=r1[$(ii*150-149):$(ii*150)] orng:=d1;
copydata irng:=r2[$(ii*150-149):$(ii*150)] orng:=d2;
}
//


Zheng
OriginLab



JUN

Edited by - j.miao on 07/24/2014 11:29:34 AM
Go to Top of Page

lkb0221

China
497 Posts

Posted - 07/24/2014 :  11:42:16 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Please try the following script, change the variable WinSize (3rd line) for different intervals

// Start
range r1 = 1; // Col(1)
range r2 = 2; // Col(2)
int WinSize = 150; // Window size
int Num = (wks.nrows / WinSize) + 1; // +1 for extra data in case
for (int ii = 1; ii <= Num; ii++)
{
range d1 = $(2*ii+1);
range d2 = $(2*ii+2);
copydata irng:=r1[$((ii - 1) * WinSize + 1):$(ii * WinSize)] orng:=d1;
copydata irng:=r2[$((ii - 1) * WinSize + 1):$(ii * WinSize)] orng:=d2;
wks.col$(2*ii+1).type = 4; // Set column be X
wks.col$(2*ii+2).type = 1; // Set column be Y
}
// End



Zheng
OriginLab
Go to Top of Page

j.miao

Germany
4 Posts

Posted - 07/24/2014 :  12:13:18 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Great!

That is what I want!

Thanks a lot!


quote:
Originally posted by lkb0221

Hi,

Please try the following script, change the variable WinSize (3rd line) for different intervals

// Start
range r1 = 1; // Col(1)
range r2 = 2; // Col(2)
int WinSize = 150; // Window size
int Num = (wks.nrows / WinSize) + 1; // +1 for extra data in case
for (int ii = 1; ii <= Num; ii++)
{
range d1 = $(2*ii+1);
range d2 = $(2*ii+2);
copydata irng:=r1[$((ii - 1) * WinSize + 1):$(ii * WinSize)] orng:=d1;
copydata irng:=r2[$((ii - 1) * WinSize + 1):$(ii * WinSize)] orng:=d2;
wks.col$(2*ii+1).type = 4; // Set column be X
wks.col$(2*ii+2).type = 1; // Set column be Y
}
// End



Zheng
OriginLab



JUN
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