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
 Including parts of columns in the formula
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Marin Vojkovic

Croatia
7 Posts

Posted - 10/22/2013 :  08:48:46 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): v7.0552(B552)
Operating System: Windows XP

Hi,

so, I have a bit older version of Origin and I cannot figure out some basic operations.
What I need to do is from one worksheet, take parts of data columns, do math to them and get results with which I fill out a column in the second worksheet.
The idea is something like this:

loop (i, 1, 30)
{
Data2!col(b)[i]=A*ln(sum(Data1!col(i)[5:25]));
}

The problem is, this doesn't work and I don't completely understand why. In searching the scripting guide (http://www.originlab.com/pdfs/Origin85_Documentation/LabTalk_Scripting_Guide.pdf) I gathered that I cannot just use col(a)[m:n] like that and that it should be defined as a range or something, but from the same document it seems that ranges are introduced in Origin8 and that I should use datasets, but I cannot find any useful examples for this.

Thank you in advance for any help.

Marin

greg

USA
1379 Posts

Posted - 10/22/2013 :  09:39:19 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Since you cannot use any range notation in your version you must use formal data notation ( WorksheetName_ColumnName ) when you address non-active sheets and the col( ) function does not work with variable names so you need the wcol function.
There is a sum function, but it calculates a number of values and stores the results in a tree. If the data display is set to a sub-range ( e.g. 5 to 25 ) then the function acts only over that range.

So,

// Data1 must be active for this loop notation
win -a Data1;
// Set range of Data1 sheet to partial
set Data1 -b 5;
get Data1_A -e end; // remember current end
set Data1 -e 25;
A = 1; // or whatever
loop (ii, 1, 30)
{
sum(wcol(ii));
Data2_b[ii] = A*ln(sum.total);
}
// Restore sheet to full
set Data1 -b 1;
set Data1 -e end;
Go to Top of Page

Marin Vojkovic

Croatia
7 Posts

Posted - 10/22/2013 :  10:05:51 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
All right, that works very nicely, thank you.
Just, a couple more questions
When I execute the script, it does not restore Data1 to its original version, the worksheet reamains cut in the specified range.
Do I maybe need to do something to enable this?

That is mostly relevant because of my other question, and that is, what if I want (and I will want that too) to calculate tha cells in the b column in Data2 with the formula

Data2_b[ii] = A*ln(sum[whole column]/sum[only specific rows, say 5:25])

Do I do something like this?

win -a Data1;

A = 1; // or whatever
loop (ii, 1, 30)
{
ss=sum.total(wcol(ii)); //calculate the sum of the whole range

set Data1 -b 5;
get Data1_A -e end; // remember current end
set Data1 -e 25;

pp=sum.total(wcol(ii)); //the sum of the subrange

set Data1 -b 1;
set Data1 -e end;

Data2_b[ii] = A*ln(ss/pp);
}

Edited by - Marin Vojkovic on 10/22/2013 10:07:56 AM
Go to Top of Page

greg

USA
1379 Posts

Posted - 10/22/2013 :  4:12:42 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The last two lines of your script apparently did not run. Did you get any Command Error?

You misunderstand the sum function.

After you run:
sum(dataset);
then the SUM object has six properties:
SUM.N
SUM.MAX
SUM.MEAN
SUM.MIN
SUM.SD
SUM.TOTAL
and you can access any of those properties, such as:
value = SUM.TOTAL

So your script might look like:
win -a Data1;
A = 1; // or whatever
loop(ii, 1, 30)
{
sum(wcol(ii)); // Sum the whole range
sumF = SUM.TOTAL; // Remember it
get wcol(ii) -e end; // remember range end
set wcol(ii) -b 5;
set wcol(ii) -e 25;
sum(wcol(ii)); // Sum the partial range
sumP = SUM.TOTAL; // Remember it
set wcol(ii) -b 1; // Restore range begin
set wcol(ii) -e end; // Restore range end
data2_b[ii] = A*ln(sumF/sumP);
}
Go to Top of Page

Marin Vojkovic

Croatia
7 Posts

Posted - 10/23/2013 :  03:32:46 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Oh, I see.

Thank you very much, this works.

in the previous case (when it didn't restore the data) I didn't get any Command error or anything, it just left the columns without the data.

Is there anywhere a manual for this older version in which I can look in the future?
When I search the web I always get the manuals for versions 8 or 9 and they have kind of scarce information and examples for these older features, so since I'm beginner at Origin I cannot figure thing out for myself.


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