Author |
Topic |
|
bur2000
Germany
36 Posts |
Posted - 12/11/2013 : 08:59:19 AM
|
Origin Ver. and Service Release (Select Help-->About Origin): 8.6
I want to add the values of three columns, then round the result to 3 digits and write it to a fourth column.
I was trying this script in Set Column Values...
double sum = Col(A)+Col(B)+Col(C); double roundSum = Round(sum,3);
Unfortunately this enters the sum of the first rows in all rows of Col(D). I tried Col(A)[i], but that doesn't work at all.
Is it possible to address the specific row in a script? |
|
snowli
USA
1386 Posts |
Posted - 12/11/2013 : 10:29:51 AM
|
Open Set Column Values dialog of the 4th column.
Enter round(col(A)+col(B)+col(C),3)
in the formula box.
It will add each row and round to 3 digits.
You defined double for sum and roundsum so they only return one value. You don't have to use the script before fomula in such case.
Thanks, Snow OriginLab Corp.
|
Edited by - snowli on 12/11/2013 10:33:00 AM |
|
|
lkb0221
China
497 Posts |
Posted - 12/11/2013 : 10:32:18 AM
|
Hi, Bur
That is because you defined the variable "sum" and "roundsum" to be double, which can only keep one numeric data.
I guess you want to let each row in col(D) has the rounded sum of column A, B and C correspondingly.
To do this, just change all the "double" to "dataset".
Zheng OriginLab |
Edited by - lkb0221 on 12/11/2013 10:33:22 AM |
|
|
bur2000
Germany
36 Posts |
Posted - 12/11/2013 : 10:46:38 AM
|
Thanks for your replies.
So when using "Set Column values" the script is only run once and then the formula box is applied to each row? I thought the script was run for each row.
Dataset also works well, but I don't understand why range can't be used in this case. I tried range and it doesn't sum the values but simply uses the values of the first column.
For example range sum = Col(A)+Col(B);
Fills the column with the values of A. |
|
|
lkb0221
China
497 Posts |
Posted - 12/11/2013 : 3:21:01 PM
|
In Set Values dialog, because your input is a dataset, Col(A)+Col(B)+Col(C), so the output will also be a dataset. So it will only run once and give all the values.
The data type of range is like a pointer, it just allows you to access your data easily in a standard way. But itself does not contain any data. |
|
|
|
Topic |
|