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
 Finding max value and writing to a new column

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
bur2000 Posted - 03/10/2014 : 07:22:20 AM
Origin Ver. and Service Release (Select Help-->About Origin): 9.0

I want to find the maximum value of a worksheet and write it to a new column. Here's my script:

// Filling the two columns from empty worksheet with some data
range activeCol = 1;
activeCol = {1:14};
range activeCol = 2;
activeCol = {15:28};

//maxValue is set to max of first column
double maxValue;
range activeCol = 1;
maxValue = max(activeCol);

// Cycle through the remaining columns and update maxValue if necessary
for ( ii = 2; ii <= wks.ncols; ii++)
{
    range activeCol = ii;
    if (maxValue < max(activeCol)) maxValue = max(activeCol);
}

// Create new column and write maxValue to it
range normalizedCol = Col("Normalized");
normalizedCol[1] = maxValue;

// Output the variable for testing purposes
type -b $(maxValue);


I have two problems/questions.

First of all, to fill the columns with data, do I really need to declare activeCol each time? I wasn't able to switch activeCol to the second column by doing activeCol = 2.

More importantly, after running the script, I end up with 14 being written to Col(Normalized). It seems like range activeCol = ii; doesn't work as supposed. Because if I substitute it with range activeCol = 2; everything works fine.
3   L A T E S T    R E P L I E S    (Newest First)
lkb0221 Posted - 03/11/2014 : 09:20:13 AM
Hi,

Yes, currently you need to specify "range" when changing.
I admit that a little confusing, I'll talk to our developers to see if there is something we can improve.

Zheng
OriginLab
bur2000 Posted - 03/11/2014 : 04:53:48 AM
quote:
The second line will put value of 2 into this cell, instead of change rr to col(B). So we should declare it's a range notation changing, when we mean it.
How do I change the range a variable is referencing? For example
range rr = 2;
rr[1] = 1;
//Now I want to set rr to point to Col(2)
rr = 2
//as you said, it's not working
So I would need to use range rr = 2? This feels a little strange to me. In other languages you can't do int a = 3; print(a); int a = 4;. This will give an error. But in Labtalk that's how you do it?

quote:
2). You would need to use $(ii) instead of just ii, in the range declaration in the loop. Sometimes LabTalk would need those substitution notations to help run-time value passing.
Thanks, is there any rule for when to use $(ii)?
lkb0221 Posted - 03/10/2014 : 09:18:14 AM
Hi#65292;

1). Assignment range variable directly will make it ambiguous.
For example:
//
range rr = col(1)[2]; // Point to the second cell of col(A)
rr = 2;
//
The second line will put value of 2 into this cell, instead of change rr to col(B). So we should declare it's a range notation changing, when we mean it.

2). You would need to use $(ii) instead of just ii, in the range declaration in the loop. Sometimes LabTalk would need those substitution notations to help run-time value passing.

Zheng
OriginLab

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