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
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 What is wrong with this script -- how to start

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
sjwu77 Posted - 10/04/2004 : 12:58:39 AM
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
5   L A T E S T    R E P L I E S    (Newest First)
sjwu77 Posted - 10/06/2004 : 7:37:59 PM
Sorry, I ignore the help manu from the software itself. Now I figured out how to do it.

Thanks
Mike Buess Posted - 10/06/2004 : 6:30:07 PM
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
sjwu77 Posted - 10/06/2004 : 5:17:16 PM
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
rlewis Posted - 10/04/2004 : 10:28:25 AM
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;
Mike Buess Posted - 10/04/2004 : 10:27:02 AM
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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000