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
 Set Condition in LabTalk
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

SamSom

2 Posts

Posted - 07/11/2018 :  09:06:21 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): OriginPro 2018; b9.5.0.193; GF3S5-3089-7905886
Operating System: Windows 64-bit

Hi,

Can you please help me to write a condition in a LabTalk script. Please consider the following table as an example. In the table the values of the first 9 rows (0-8th row number) of column B are same as that of column D, while the rest of the values of column B (from 9-19th row number) are same as column C. Here, A has x values, while B, C and D having the y values.

I want to make a condition such that going along the column B when the value of column B matches for the first time with column C, it will print the value of that particular row of column A. I want to use the obtained value to draw a vertical line in the graph using the labtalk command “addline type:=0 value:=* select:=1 name:=vline1”, in which the “*” is the obtained value from column A. I want to use this condition in a loop.

A B C D
0 -877.37112 -877.38525 -877.37112
1 -877.38623 -877.40086 -877.38623
2 -877.39142 -877.40601 -877.39142
3 -877.38947 -877.40368 -877.38947
4 -877.38835 -877.40105 -877.38835
5 -877.393 -877.40359 -877.393
6 -877.39869 -877.40626 -877.39869
7 -877.39793 -877.40358 -877.39793
8 -877.38799 -877.39224 -877.38799
9 -877.38121 -877.38121 -877.3779
10 -877.37988 -877.37988 -877.37594
11 -877.38913 -877.38913 -877.37992
12 -877.39817 -877.39817 -877.38643
13 -877.40141 -877.40141 -877.38795
14 -877.39862 -877.39862 -877.38373
15 -877.39684 -877.39684 -877.38004
16 -877.40329 -877.40329 -877.38317
17 -877.41459 -877.41459 -877.38931
18 -877.42108 -877.42108 -877.38884
19 -877.41834 -877.41834 -877.37799

Thank you in advance.

Hideo Fujii

USA
1582 Posts

Posted - 07/11/2018 :  4:07:45 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi SamSom,

How about this snippet?
///////////////////////////////////////
//On active worksheet
range ra=col(A);
range rb=col(B);
range rc=col(C);
int found=0;         //Flag on finding
int nr=rb.getSize();
for(ii=1; ii<=nr; ii++) {  //Loop
  if(rb[ii]==rc[ii]) {     //Test
    found=1;               //Set flag
    break;                 //Exit from loop
  }
}
if(found) {
  window -a Graph1;  //Activate your graph
  addline type:=0 value:=ra[ii] select:=1 name:=vline1;
}
else type -b Not Found;
///////////////////////////////////////

Hope this helps.

--Hideo Fujii
OriginLab
Go to Top of Page

SamSom

2 Posts

Posted - 07/12/2018 :  04:51:35 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Dear Hideo,

Thank you for your help. I tried to use the script but it is showing the message "Not Found" even though column B matches with column C as I showed in my table.
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 07/12/2018 :  05:50:10 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Might be due to rounding so two values looked the same but actually different.

Maybe replace

if(rb[ii]==rc[ii])


with

if(round(rb[ii],8)==round(rc[ii],8))


CP
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