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
 What is wrong with this script -- how to start
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

sjwu77

USA
Posts

Posted - 10/04/2004 :  12:58:39 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi, everyone,

I try to use labtalk script to substract a column with it's mean value over it's 10000 elements. here is my script:

col(2)=col(2)-ave(col(2),10000);

Expect the first row gives the correct result, the other rows gives bars '-'.

I guess I made an obvious mistake but I just cannot figure out. Could anyone give me a hint where I should start to learn the scripts?

Thanks,

Saijun

Mike Buess

USA
3037 Posts

Posted - 10/04/2004 :  10:27:02 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Saijun,

From help file...
quote:
The ave(dataset, size) function breaks dataset into groups of size size, finds the average for each group, and returns a range containing these values.
If dataset has N rows then ave(dataset,size) returns a dataset with N/size rows. In your case N=size and ave() returns a dataset with one row. Subtract that from the original dataset and you get a number in the first row and missing values '--' in the rest. If you want to subtract the mean from all elements you must do so as a scalar. This is probably the easiest way to do that..

sum(col(2)); // find sum, mean, etc.
col(2)-=sum.mean; // subtract the mean from all elements

Mike Buess
Origin WebRing Member
Go to Top of Page

rlewis

Canada
253 Posts

Posted - 10/04/2004 :  10:28:25 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
If you are trying to subtract from col(2) the mean value of all of the elements in col(2) then the following LT sequence will do the job

sum(col(2));
col(2)-=sum.mean;
Go to Top of Page

sjwu77

USA
Posts

Posted - 10/06/2004 :  5:17:16 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks Mike and rlewis.

All right, now it works. The next thing I want to do is to repeat the operation for each even column, I wrote something like:

loop(i,1,100){sum(col(i*2);col(i*2)-=sum.mean;};

It doesnt work again...

Where should I look at to get some basic training on the script programming?

Thanks again
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 10/06/2004 :  6:30:07 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You must use a column name or number as argument for col()... expressions won't work. Use wcol() when you need expressions...

loop(i,1,100){sum(wcol(i*2)); wcol(i*2)-=sum.mean;};

In addition, you had an unmatched parenthesis in your script. Fixed above.

As for LabTalk training...

1. Examples are scattered throughout your LabTalk Progamming Guide.

2. You'll find programming resources at OriginLab's web site...

http://www.originlab.com/index.aspx?s=9&lm=+71

Many good script examples are in the Knowledge Base you'll find there.

3. There are more examples and tips from Origin users at the Origin WebRing (see my signature).

4. If you have Origin 7.0 or 7.5 you'll find some tutorials on the Help menu. (Although the emphasis of those tutorials is Origin C rather than LabTalk.)

Mike Buess
Origin WebRing Member
Go to Top of Page

sjwu77

USA
Posts

Posted - 10/06/2004 :  7:37:59 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Sorry, I ignore the help manu from the software itself. Now I figured out how to do it.

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