Introduction
We have a customer who wants to detect the position of jumps in his signal data and put that information into a worksheet for further use. While it can be done in older versions of Origin, Origin 2021b makes it easy to do- it only requires one function call in a Set Column Values formula.
The function is idx()
and it is new in Origin 2021b. It accepts a "column conditional expression" and returns a dataset
(vector) of integers containing the one-based row index of all the records that meet the condition.
Here are some examples of column formulas using the function:
idx(B==100) // Returns indices of values in B that equal 100 idx(B>=20 && B<=50) // Returns indices of values in B are between 20 and 50 idx(left(A,5)$ == "Chris") // Returns indices of values in A where first 5 letters are "Chris" idx(diff(B)>1) // Returns indices in B where the difference between one value and the next value is greater than 1
As you can see, the function is able to accept other functions as part of the "column condition expression".
So, now let's apply the idx()
function to a few example signals to highlight how Origin 2021b can make it easy for the customer to detect jump positions .
Getting Started
When I refer to a "jump", I mean something like what is displayed in the graph to the right. At some distinct point, the data literally jumps- it makes a clear, abrupt transition. In the case of this graph, there are four jumps and each has a jump start and jump end.
These transitions are, of course, detectable in Origin. We can use the diff()
function (documentation) to compare a value in a column (e.g. 0
) to the next value (e.g. 5
) and then return the difference. In the case on the right, diff()
would calculate many zeros, four 5
's (jump starts), and four -5
's (jump ends).
With that knowledge, we can leverage diff()
and idx()
in combination in a Column Values formula like: idx(diff(B)>1)
. The formula says "Get the row indices from column B where the difference between one record and the next is greater than 1".
In all the coming examples, the worksheet arrangement is the same for all (see below). Observe not only are there X & Y columns, there is a column jump index formula result. There are two more columns- one containing the X values for the jump indices and one containing the Y values. Only the Columns Values formula will change a little. Note: On the graph, the jumps are denoted by a red droplines.
Examples
Note: All the examples below are available in the downloadable companion project file.
Bonus Example
There is another variation on this. What if you simply want the last jump in a series? Again we'll use idx(diff(B)>1)
but with a small modification. To get the last item returned by the code, change it to this: idx(diff(B)>1)[0]
. In this case, [0]
mean the last value in a dataset. So that code says "Get the last row index from column B where the difference between one record and the next is greater than 1".
Such code can be used in a cell formula as illustrated below.
Conclusion
Thanks for taking the time to read this post. I hope it provided valuable information.