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

HaroldPit2

2 Posts

Posted - 12/14/2011 :  4:34:28 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release: Origin Pro 8.5.0G SR1
Operating System: WinXP

I want to average(arithmetic mean) over several columns. I want this to be done using a user input, that specifies over how many columns the averaging has to be done and with which column to start. I tried various things and I have a rough idea what I want:

loop (i,$(firstaveragingcolumn), $(firstaveragingcolumn) + $(numberofcolumns))
{
	%M=$(i);
	%N=Col;
	%O=%M%N;
	range %O=wcol(i+1);
}
range colmed = Averages!col(2);
colmed = (col1+col2+....)/$(reps);


I essentially need a loop that spits out all the columns defined per the variables for further processing. I noticed that the ranges are only existent inside the loop, so I'm at a loss what to do here.

In case I didn't get my point across please ask for clarification.

LabTalk user

USA
35 Posts

Posted - 12/15/2011 :  11:40:09 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

You can try forcing global scope on the variables.
@global = 1; //This forces all following variables to global scope
@global = 0; //Sets all following variables to standard scope
For more on scope see: http://wiki.originlab.com/~originla/wiki/index.php?title=LabTalk:Data_Types_and_Variables

If that doesn't work, try using non-string register variable names. I've noticed weird things happen when I use string registers too much.
See: http://wiki.originlab.com/~originla/wiki/index.php?title=LabTalk:String_registers

Hope this helps!

-P
Go to Top of Page

couturier

France
291 Posts

Posted - 12/16/2011 :  04:46:21 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can use the following script:

int colbegin=2, colend=6; // define here begin and end column
range activesheet=!, result=Averages!2; // define active sheet for performing average, and where to put result
sum(%(activesheet),colbegin,colend); // compute stats from begin to end cols
result=_mean;
del _mean; // the sum function will compute various stat parameters
del _sd; // that are stored in those hidden datasets
del _max; // I delete them after to clear up memory
del _min; // Before deleting, you can also use any of them
del _range;
del _npts;

This method is the fastest as far as I know
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