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
 Origin Forum
 If-Then-Function under Origin
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Lars84

Germany
5 Posts

Posted - 03/12/2012 :  08:38:15 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): Origin 8.1G SR3
Operating System: Windows XP Prof.

Hello I´m a newbie in Origin an programming, but I have to work with Origin because I got big data files. Befor I worked with Excel and there it was possible to implement IF/Then-Function or a combination of If, And and Or function in a working sheet. Now I want to do the same in Origin but I didn´t know how. So coul anybody help me?

What I want to do in detail: I want to combine a If function with a And and Or function in the way, that when in row A a value above 0.05*Maximum of the howl row is detected write a 1 at that point in row B. If not write a zero.
This i want to combine in the way that when in row A a value above 0.05*Maximum of the howl row is detected OR the value before the detaction of this maximum in row B is 1 AND if the following value in row A is greater then 1, then print a 1 at that point in row B. I hope you understood what I want to do. If not don´t hesitate and ask me.

Thanks and regards, Lars

greg

USA
1378 Posts

Posted - 03/12/2012 :  1:39:02 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The conditional 'AND' in LabTalk is '&&' while the conditional 'OR' is '||'.

Your looking 'ahead' as well as 'back' suggests you need to loop twice through your data. Once over all the data (setting 'B' to either 1 or 0 based on 'A') and again from row 2 to the next-to-last row (setting 'B' to 1 if the previous B is 1 and the next A is greater than 1).

If so, then the code would look like this:

// Declare ranges for columns A and B
range ra = col(A);
range rb = col(B);
// Find maximum of column A
vmax = max(ra);
// Calculate the test value
vtest = 0.05 * vmax;
// Now loop over all the rows for the first test
loop(row,1,ra.GetSize())
{
if(ra[row] > vtest) rb[row] = 1;
else rb[row] = 0;
}
// Loop again over N - 2 rows for the second test
loop(row,2,ra.GetSize()-1)
{
if(rb[row-1] == 1 && ra[row+1] > 1) rb[row] = 1;
}
Go to Top of Page

Lars84

Germany
5 Posts

Posted - 03/13/2012 :  03:12:28 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi greg,

that is exactly what I´m looking for. I thank you for your help!

If it´s possible, I had another two questions for this topic.
1.) How can I reduce the produced data? For example the data I produced looks in the way:

Time Row(A) Row(B)
0 0 0
0.001 0.1 0
0.002 0 0
0.003 0.2 0
0.004 0 0
.
.
0.1 0.1 0
0.101 20 1
0.102 20.4 1
0.103 19.9 1
.
.
0.2 20.1 1
0.201 0.1 0

and so on. And now I only want to have the Time row and the row(B) in a new Book AND there should only be events taken where row(B) chances from 0 to 1 and back. So it should be look like that way:

Time Row(A) Row(B)
0 0 0
0.1 0.1 0
0.101 20 1
0.2 20.1 1
0.201 0.1 0

2.) When I have two data sets in different working books that I would like to converte. How could I do that with the logic above? I know, I could run it seperatly for each book, but I want to automatize the procedure AND I want to create a new book in which in row B the value of row B of book1 and in row C the value of row B of book2 is printed.

I hope you know what I mean and it´s not too much asked!
Regards, Lars

Edited by - Lars84 on 03/13/2012 04:10:18 AM
Go to Top of Page

Hideo Fujii

USA
1582 Posts

Posted - 03/13/2012 :  11:28:18 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Lars,

There may be a smarter way, utilizing the conditional operator: 
  <Condition>?<VALUE_on_TRUE>:<VALUE_on_FALSE>
please try the following procedure (See the sample in the screenshot): 

1) Add two columns. (Column D and E).
2) Using the Set Column Value tool for column D to detect the row of changing col(C). I.e.:
  abs(col(C)[i+1]-col(C)[i])
3) Using the Set Column Value tool for column E to detect the row of consequent changing col(D). I.e.:
  col(D)==1/0?1:(col(D)[i+1]==1?1:col(D)[i])
  (Here, the first test for the missing value(=1/0) was set only for the first row.)
4) Using the Worksheet Query tool ("Worksheet: Worksheet Query" menu), extract the rows which have the value 1 at column E.



Hope this works as what you envisioned.

--Hideo Fujii
OriginLab
Go to Top of Page

Lars84

Germany
5 Posts

Posted - 03/14/2012 :  06:19:33 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Hideo,

thanks for your help! Yes that is exactly what I wanted to do. But is it possible to automazie this procedure?

Lars
Go to Top of Page

Hideo Fujii

USA
1582 Posts

Posted - 03/14/2012 :  10:40:25 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Lars,

One way to automatize this is to make an analysis template with recalculation settings. 
Since the Worksheet Query tool is actually the "wextract" x-function, you can put this 
as a part of recalculation such that (as in the screenshot below): 

1) Add an extra column, F. Open its Set Column Value tool, and enter the following 
command into the "Before Formula Scripts" box: 
  wextract iy:=[Book1]Sheet1!(1:end) 
    settings.stAlias.Cols:=5 
    settings.stAlias.AliasNames:=E 
    settings.stCondition.Condition:="E=1" 
    settings.cols:="0|1|2";
  This command does the exactly the same in my previous post. No formula in the main box!
  Set this Set Col Values tool's Recalculation mode to "Auto" (as the green lock icon tells).
  Click OK to save.
  (For the infomation about wextract, open the X-function help, and go to: 
     X-Function> Data Manipulation> Worksheet> wextract )
2) Also for columns D and E, set their Set Col Values tool's Recalculation mode to "Auto". 
  Try to update the data in columns C, or import data into column A, B, and C, 
  and observe that a new extracted worksheet is created. 

3) Save the worksheet as an Analysis Template by "File: Save Workbook as Analysis Template" menu. 

Now, you always open this template, and enter your new data, you get the result automatically.



--Hideo Fujii
OriginLab

P.S. Sorry for that there was a type in my previous post. The formula for column should read: 
  abs(col(C)[i]-col(C)[i-1])

Edited by - Hideo Fujii on 03/14/2012 10:43:09 AM
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