Showing results for 
Search instead for 
Did you mean: 

Detect array position of a value change

Go to solution



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?

0 Kudos
Message 1 of 6

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.

Message 2 of 6

Wire OldVal and NewVal into Does Not Equal.  That gives you an array of booleans where all true values are elements that changed.

Message 3 of 6
Accepted by topic author md12g12

Yep, a simple XOR with the "Old Value" will result in a TRUE in only the place that was changed.

There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 4 of 6

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.

0 Kudos
Message 5 of 6

Have already voted and commented there in my travels today 😉


And thanks, will make it more general.

0 Kudos
Message 6 of 6