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
 using variable in col()
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

RiverFalls

USA
36 Posts

Posted - 08/27/2019 :  5:50:21 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin):
Operating System:Win 10

We would like to use a variable in col() (as shown below in the script), but we cannot get it to work. How can we use a variable in this way?

Thank you,
Lowell

-----------------------------------------

range aa=%C;
%A = aa.lname$;

string CERSspectraBK$= Spectrum.txt;
string CERSspectraSHT$ = Results;
string PeaksBK$ = SplitSpectra;
string PeaksSHT$ = Results;

string fixedname$ = CheckPeaks;

int activecol = colnum(%C);
int nextcol = activecol+1;
int Spectracol = nextcol/2 +1;


plotxy iy:= [CERSspectraBK$]CERSspectraSHT$!(1,$(Spectracol)) ogl:=[<new template:=CheckPeaksGraph name:=CheckPeaks>]ogl:=[CheckPeaks] plot:=200;


int numPeaks = %([PeaksBK$]PeaksSHT$!col(3)[C]$);

//In the line above we would like to use the variable activecol instead of the value 3, like:
// int numPeaks = %([PeaksBK$]PeaksSHT$!col(activecol)[C]$);
//but this doesn't work.

type "activecol = $(activecol)";
type "numPeaks = $(numPeaks)";
type "%A";
for(int i = 1; i <= numPeaks; i++){
draw -c 1 -d 0 -l -v aa[i];
}

yuki_wu

896 Posts

Posted - 08/27/2019 :  10:54:42 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Use $ to convert numeric to string, for example:
int aa = 3;
col($(aa))[L]$ = "New Long Name" //Set long name for the 3rd column

Regards,
Yuki
OriginLab
Go to Top of Page

RiverFalls

USA
36 Posts

Posted - 08/28/2019 :  10:28:35 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
We tried that already in each of the following forms:

int numPeaks = %([PeaksBK$]PeaksSHT$!col($(activecol))[C]$);

and

int j =3;
int numPeaks = %([PeaksBK$]PeaksSHT$!col( $(j))[C]$);

neither one works, which is why we are so confused!

Lowell

Go to Top of Page

YimingChen

1669 Posts

Posted - 08/28/2019 :  12:27:04 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Instead of using col(activecol), can you use wcol(activecol)? Thanks.
https://www.originlab.com/doc/LabTalk/ref/WCol-func

James

Edited by - YimingChen on 08/28/2019 12:28:11 PM
Go to Top of Page

RiverFalls

USA
36 Posts

Posted - 08/28/2019 :  12:33:34 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
James,
That worked exactly the way we want. Thank you!
Lowell
Go to Top of Page

yuki_wu

896 Posts

Posted - 08/29/2019 :  01:44:56 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi All,

Sorry that I wasn’t aware Lowell desired to use % with an embedded $. For now, it is not allowed the embedded use of % and $. Instead of the workaround that James mentioned, we can use string registers to avoid this:
int aa = 3;
%A = col($(aa))[L]$; 
int aa = %A

Regards,
Yuki

OriginLab
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