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
 Script to extrapolate y values from many 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

surjpanj

Canada
18 Posts

Posted - 06/02/2021 :  09:11:33 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 2018
Operating System: Win 10

Hi,

I need a script that would extrapolate y values from a specified set of x values (i.e., function Extrapolate Y from X in the Analysis/Mathematics menu), run through specified columns (e.g. Col(C), Col(E), Col(G),...) and write the extrapolated values in a new sheet. The extrapolated values should be written only in one column (i.e., Col(C) followed by Col(E) values, Col(G) values, etc). I would also need that extrapolated values are rounded to only one decimal place and if the value is negative, it should be set to zero. The script should run through all workbooks in the project.

A lot to ask I know but I appreciate the help.

Thanks,
Matt

YimingChen

1669 Posts

Posted - 06/02/2021 :  12:14:06 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Please refer to this X-function page on interpolation.
https://www.originlab.com/doc/X-Function/ref/interp1

To loop through all workbooks, please use
doc -e W {}

Please refer to https://www.originlab.com/doc/labtalk/ref/document-cmd#-e_object_.7Bscript.7D.3B_Execute_the_given_script_for_all_objects

For further help, please contact us use the ticket system.
https://www.originlab.com/restricted/support/index.aspx?c=3

James
Go to Top of Page

surjpanj

Canada
18 Posts

Posted - 06/03/2021 :  07:49:09 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi James,

thanks for pointing me to the references. So far I managed to write a script, which applies the extrapolate function on the selected columns of the worksheet (see script below). However, the extrapolated values should be written in a new sheet (possibly renamed as "original sheet name"_a). Then, the new columns should be arranged one after another as a one long column (maybe in another sheet with name "original sheet name"_b). Can you please help me solve this?

I have hundred worksheets where I need to do such processing. Finally, I will need to export the long columns into individual txt files (named as e.g. "original sheet name"_b.txt ).

Thanks,
Matt

doc -e W {
for (j = 4; j <=wks.nCols; j = j + 2)
{interp1 ix:=Col(1) iy:=wCol(j)}
}
Go to Top of Page

YimingChen

1669 Posts

Posted - 06/03/2021 :  11:51:59 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
1. you may first prepare a workbook to save the result to columns. e.g.
interp1 ix:=Col(1) iy:=wCol(j) ox:=[book2]Sheet2!<new>;


2. Then you may want to stack all cols into one long column.
wstackcol -r 2;


3. To export worksheet, use
expASC path:="C:\test.dat"


Please also check the details of the X-function that is used.

James

Edited by - YimingChen on 06/03/2021 11:53:36 AM
Go to Top of Page

surjpanj

Canada
18 Posts

Posted - 06/04/2021 :  09:51:48 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks James! Please help me solve several more issues.

1. If I use script: for (j = 4; j <=wks.nCols; j = j + 2) {interp1 ix:=Col(1) iy:=wCol(j) ox:= [book2]Sheet2!<new>}; then the script runs only on the first column. I need to manually create book2 for script to run over all columns. What command can I use to create a new woorkbook and then rename it the same as the original woorkbook with an extension "_b"?

2. wstackcol -r 2; this command only works if I manually highlight all the columns. The results are given in two columns where the first column contains useless information. I only need data on the second column.

3. The data in the long column should be rounded only to one decimal place and if the value is negative, it should be set to zero.

As I mentioned, I literally have more than 100 workbooks where I need to do such processing therefore the script should automate all of the above steps.

I appreciate your help.
Matt
Go to Top of Page

YimingChen

1669 Posts

Posted - 06/04/2021 :  4:41:18 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
For further help, please contact us using the ticket system below and provide your serial number in the message. Thank you.
https://www.originlab.com/restricted/support/index.aspx?c=3

James
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