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
 Including parts of columns in the formula

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
Marin Vojkovic Posted - 10/22/2013 : 08:48:46 AM
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
4   L A T E S T    R E P L I E S    (Newest First)
Marin Vojkovic Posted - 10/23/2013 : 03:32:46 AM
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.


greg Posted - 10/22/2013 : 4:12:42 PM
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);
}
Marin Vojkovic Posted - 10/22/2013 : 10:05:51 AM
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);
}
greg Posted - 10/22/2013 : 09:39:19 AM
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;

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