Author |
Topic  |
|
hfkenny
China
Posts |
Posted - 12/18/2006 : 05:23:38 AM
|
Origin Version (Select Help-->About Origin): 7.5 Operating System: WinXP
Dear all:
I got 2 problems about "Set Columns Values":
1. Is it possible to set a column values according to the values of another column? Saying, the values of column B will be 0 when the values of column A is negaetive and vise versa.(row by row)
2. How can I associate my own C code with "add function" button? or how can I add a new function of my own into the "add function" downlist?
Thanks!!
hfkenny |
|
Mike Buess
USA
3037 Posts |
Posted - 12/18/2006 : 06:52:02 AM
|
hfkenny,
1. Use the ternary operator. This sets col(B) to value1 if col(A)<0 and value2 otherwise.
col(B) = col(A)<0 ? value1 : value2
2. You can't add you function to the Add Function list but you can use it in the Set Column Values expression anyway as long as it's compiled...
col(B) = MyFunction(col(A));
Mike Buess Origin WebRing Member |
 |
|
hfkenny
China
Posts |
Posted - 12/18/2006 : 9:21:07 PM
|
Dear Mike:
I tryed the ternary operator and it indeed works! I wonder how you can know this! Could you please give me some clue to find a comprehensive usage handbook about Origin? Anyway, Thank you very much for your help and I also give my best wish to you for the coming Christmas and New year!
hfkenny
|
 |
|
zachary_origin
China
Posts |
Posted - 12/18/2006 : 9:50:50 PM
|
Hi hfkenny,
Mike knows so many deep things of Origin because he has used it for more than ten years. He almost knows everything for Origin... :)
To be familiar with Origin, I think the most useful handbook is the Help file in Origin though it contains many many chapters...
Zachary OriginLab Technical Services. |
 |
|
Leo_Li
China
Posts |
Posted - 12/18/2006 : 11:31:06 PM
|
Try this tutorial:
Origin Menu: Help->Tutorial Tutorial 15: Adding a New Function (and call it in "Set Col Values" dialog)
Leo
|
 |
|
Mike Buess
USA
3037 Posts |
Posted - 12/19/2006 : 09:59:03 AM
|
Thanks, Zachary... flattery will get you everywhere. :) The ternary operator is indeed in the programming guide.
LabTalk Language Reference > Overview... > Operators > Conditional Operators
There Origin's tReplace function is also discussed. It is more powerful and faster than the ternary operator but is also more difficult to use.
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 12/19/2006 09:59:50 AM |
 |
|
hfkenny
China
Posts |
Posted - 12/21/2006 : 05:02:20 AM
|
Dear all:
Thank you for your kind reply.
I've got a new problem now. When calculation of "arctan(a/b)", the result has to be modified according to the value of b: if b>0, no modification is needed; if b<0, the result should be added with pi(3.14159),and if b=0, then the value of "a" should be taken into consideration: a>0, the result should be +pi/2; a<0, the result be -pi/2 ,and a=0, a missing number. How can I realise this in "set column values"? I tried treplace function and it seems not to work.
hfkenny |
 |
|
zachary_origin
China
Posts |
Posted - 12/21/2006 : 05:36:08 AM
|
Hi, You may use the method 2 Mike has suggested. Leo has mentioned a tutorial for how to add a funtion.
Zachary OriginLab Technical Services. |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 12/21/2006 : 09:15:06 AM
|
Hi hfkenny,
tReplace acts on an entire dataset and will not work in a Set Column Values expression. You must use it from the script window.
Mike Buess Origin WebRing Member |
 |
|
hfkenny
China
Posts |
Posted - 12/23/2006 : 10:08:52 AM
|
Hi,Mike:
I tried "treplace" function and found it can work in a "Set Column Values" expression. you can try the example listed under "programming / tReplace" item. But this seem no help to my problem.
hfkenny
|
 |
|
|
Topic  |
|