Is there any way to find the position in an array of a value change? I have a boolean array (which I convert to 0,1), I can then find the max, min to give a location of a change, but this only works if the change is "earlier" than any previous changes. I thought about using a shift register to compare the previous state of the array with the current one, but still see no way to extract the position of the change?
p.s I have attached my vi in case it helps. There is panel of LED's with are used to track the position of something. By clicking a new position I want to be able to have the array position (to convert to a voltage), but also be able to find the position of an LED that is switched off as well. Does this make sense?
Solved! Go to Solution.
If you exclusive-OR two boolean arrays, then in the resulting array all of the array elements that are unchanged between the two arrays will be false, and all of the elements that differ (because they've changed, either false to true, or true to false) will be true. The XOR will basically output a map of the changes between the two input arrays.
Wire OldVal and NewVal into Does Not Equal. That gives you an array of booleans where all true values are elements that changed.
Yep, a simple XOR with the "Old Value" will result in a TRUE in only the place that was changed.
While you are at it, feel free to vote for this idea. 😄
On a side note, I would use "not equal" instead of XOR so you don't need to learn new tricks if you try to apply the same logic to see what element changed in a DBL or Integer array. (XOR would break for DBL and would give you a bitwise answer for integers). It is also less nerdy. 😄
Often the terminal is actually wired elsewhere, and I typically just compare oldval and newval, both from the event data node. Also, the location should probably be blue.