LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to (logical) compare two arrays

Hello,

i have two boolean arrays.

A[0,1,1,1,0,1,0,0,1,0,0,0,0]

B[0,1,1,1,0,1,0,0,1,0,1,1,0]

 

They have same size. The only difference are the last two 1,1 in array B.

What do i have to do to get an array that contains only the differences?

C[0,0,0,0,0,0,0,0,0,0,1,1,0]

 

Thx

0 Kudos
Message 1 of 7
(3,355 Views)

hi onlyone,

have you tried the Exclusive Or Primitive?

 

http://zone.ni.com/reference/en-XX/help/371361H-01/glang/exclusive_or/

Message 2 of 7
(3,344 Views)

undefined

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 3 of 7
(3,339 Views)

... And if you want less obscure code, simply use a "not equal" from the comparison palette, same result. 🙂

 

"Not equal" is much easier to understand for a new programmer than the geeky " xor". It is also more universal and works for arrays of any datatype. For example xor will do bitwise for integers and won't work for DBL, != will always give you a boolean array showing which elements differ.

Message 4 of 7
(3,310 Views)

@altenbach wrote:

... And if you want less obscure code, simply use a "not equal" from the comparison palette, same result. 🙂

 

"Not equal" is much easier to understand for a new programmer than the geeky " xor". It is also more universal and works for arrays of any datatype. For example xor will do bitwise for integers and won't work for DBL, != will always give you a boolean array showing which elements differ.


As long as you compare elements (Default) there is a Right Click Menu option to compare aggrigates that you do not want to use in this case.


"Should be" isn't "Is" -Jay
0 Kudos
Message 5 of 7
(3,295 Views)

Yes, I was talking exclusively about "compare elements".

 

XOR does not have an equivalent option to "compare aggregates" anyway, we would need to add an "OR array elements" afterwards.

0 Kudos
Message 6 of 7
(3,284 Views)

The concern was:  "Sometimes newer users just copy and paste primitives from existing code untill they learn to navigate the palettes."    Or I would not have mentioned it.  Oh! the trouble they can get into that waySmiley Surprised


"Should be" isn't "Is" -Jay
0 Kudos
Message 7 of 7
(3,275 Views)