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
 Programming macros
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Gabelach

4 Posts

Posted - 06/28/2013 :  5:28:31 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): OriginPro8
Operating System: win 8

Hello to everyone,

I have just started using OringPro 8 at my university for my thesis and I have been confronted by some tedious tasks.
I have seen that it is possible to use labTalk for programming macros (by editing the custom.ogs file) but I'm having some issues.

My aim is to automate the process of deleting a couple hundreds useless columns form various csv files; the columns are always in the same positions, so the process should be pretty easy;
This said, the problem is that I can't find a function to delete a column...

Any help would be appreciated! Thanks!

greg

USA
1378 Posts

Posted - 07/01/2013 :  09:50:25 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can delete a column by
Long Name
del col("Sample 3")
Short Name
del col(F)
Index (from 1)
del col(6)
or use a variable when deleting by index
NextCol = 6;
del wcol(NextCol);
Go to Top of Page

Gabelach

4 Posts

Posted - 07/01/2013 :  4:30:53 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you!
You allowed me to save up a lot of time!

But now I would like to do something more.
I have seen that via the command lr I could get the slope and intercept of the fitted data.

Is it possible to get a new column where linear fit has been subtracted?
Moreover, the linear fit should be done only between the first four points (but I think I could set this with the "-b dataset" option, right?).
Go to Top of Page

greg

USA
1378 Posts

Posted - 07/02/2013 :  2:30:58 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Assuming a worksheet with two columns : A and B

lr col(B) -b 1 -e 4; // Linear fit based on first four points
wks.AddCol(Fit); // Add a column for linear fit data
col(fit) = lr.b * col(A) + lr.a; // Calculate
wks.AddCol(Residuals); // Add a column for residuals
col(Residuals) = col(B) - col(Fit); // Subtract fit from data

This is very 'old school' and we recommend using the fitlr X-Function instead.
Go to Top of Page

Gabelach

4 Posts

Posted - 07/02/2013 :  4:17:38 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you again, this works perfectly.

I was also trying to change a column attribute (from Y to X), but the command

wks.Columns(C6).SetType(OKDATAOBJ_DESIGNATION_X); // An X column

doesn't seem to work.


And I was also wondering if there is a function similar to Datasheet-FindCol which operates on columns. For example, in order to find the positions of zeroes in a column.
Could I use the vfind function? I'm not sure if the returned values can be saved in order to be used later...
Go to Top of Page

greg

USA
1378 Posts

Posted - 07/05/2013 :  4:38:07 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Try to keep track of where you are in the Help resources. Your example:
wks.Columns(C6).SetType(OKDATAOBJ_DESIGNATION_X); // An X column
looks like it came from Origin C Help documentation.

The LabTalk equivalent would be:
wks.col$(colnum(C6)).type = 4;

vfind can be used to get all rows where a value of 0 exists in a column (or even all values within a certain distance from 0):

dataset dsIndexes; // Dataset to store rows where found
vfind -r 0 ix:=[Book1]"Sheet1"!C6 value:=0 ox:=dsIndexes tol:=1E-2;
ty -l "Zero +/- 1E-2 found in rows ";
loop(ii,1,dsIndexes.GetSize())
{
if(ii==1) ty -l $(dsIndexes[ii]);
else ty -l ,$(dsIndexes[ii]);
}
type;
Go to Top of Page

Gabelach

4 Posts

Posted - 07/06/2013 :  1:04:25 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Yes, it does come from the Origin C section. But, since the syntax seemed similar to the example you gave me before, I thought it might work.

Anyway, thank you again, I will see if I can use your last code with some minor changes (as I have found, the column not always has the minimum in zero)

Thanks!
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