Author |
Topic |
|
zango24
India
Posts |
Posted - 02/24/2015 : 12:56:08 PM
|
Origin Ver. 8.6 and Service Release (Select Help-->About Origin): Operating System:win 7
Dear all, I am back with another query. I have a column with several numbers run from row 1 to row 800. Each row contain random numbers. Some with positive sign and some with negative sign. But these numbers and their sign occur randomly. I want to count how many times there is a transition between positive to negative and negative to positive.
Eg: column A contain these random numbers: 12 54 -76 32 56 1 -44 -3 -56 -12 41 44 84 -76 -12 -54 42 54 -76 46
So if I do it manually,it is simple. Like: Positive to negative: 04 times. Negative to positive: 04 times.
Any method to do it automatically?
Cheers, Zen |
|
Hideo Fujii
USA
1582 Posts |
Posted - 02/24/2015 : 2:58:23 PM
|
Hi Zen,
One way is to use Set Column Values tool as below:
Here, the columns F and G show the number of cases of Negative->Positive, and Positive->Negative, respectively. Of course, you can consolidate formulae to fewer.
--Hideo Fujii OriginLab
P.S. You can also run the Discrete Frequency on the column C.
P.P.S. The above method should work with 0's if it's okay not to count the transition to/from a zero. If you need to count the transitions like [+,0,...,0,-] , [-,0,...,0,+], [+,0,...,0,+], or [-,0,...,0,-], you need more sophisticated logic. |
Edited by - Hideo Fujii on 02/25/2015 09:28:20 AM |
|
|
zango24
India
Posts |
Posted - 02/26/2015 : 1:18:23 PM
|
Hi Hideo, Thanks for your quick response. Your suggestions are working wonderfully. So its somehow better than manual calculations and counting. But it involves treating each column as one at a time. I wonder if there is a way around to get the work done for multi columns of the same worksheet..... and if possible... multi columns in multi worksheets....
I know I am becoming bit greedy sorry about that.... Thanks for your support, Cheers Zen |
|
|
Hideo Fujii
USA
1582 Posts |
Posted - 02/26/2015 : 2:12:48 PM
|
Hi Zen,
No need to say sorry as this is a very natural course that many people take to consider scripting. The following script does such repetitive tasks for multiple columns in a worksheet using loops://////////////////////////////////
ncols=wks.ncols;
for(ii=1; ii<=ncols; ii++) {
range rr=wcol(ii);
nrows=rr.getsize();
nneg=0;
npos=0;
for(jj=2; jj<=nrows; jj++) {
if(wcol(ii)[jj-1]<0 && wcol(ii)[jj]>0) npos++; //count up positives
else if(wcol(ii)[jj-1]>0 && wcol(ii)[jj]<0) nneg++; //count up negatives
}
type -a col:$(ii) colname:%(wks.col$(ii).name$) npos:$(npos) nneg:$(nneg);
} //////////////////////////////////
Maybe it's a time for you to challenge scripting so that you can freely create/modify it for your own needs? 8-)
--Hideo Fujii |
|
|
|
Topic |
|
|
|