From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

array elements equal to each other?

Solved!
Go to solution

Hi,

 

Maybe a very simple question but i haven't found the answer here...

 

I have a 1D Array with let's say 4 elements, and if all elements are equal to each other

(1,1,1,1)  then it should return true

if one element is other then the rest

(1,2,1,1)  it should return false...

 

How to build this simple?

 

Best regards,

Thijs

 

 

0 Kudos
Message 1 of 8
(4,833 Views)

I got this thus far...?

 

EqualElements.png

 

But maybe there is something more simple?

 

regards,

Thijs

0 Kudos
Message 2 of 8
(4,828 Views)

Hi Thijs,

 

you need to compare one element of the array with the remaining ones:

check.png

 

To your own approach:

- RubeGoldberg due to indexing the same element of the array in each iteration

- RubeGoldberg due to using a loop where polymorphism will do the same

- wrong labeling of the output: you need to AND all booleans, but not ORing them

- the AutoCleanup tool is pretty good at such small snippets…

😄

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 8
(4,827 Views)

Nice,

 

But i came to realise that there's a bigger challenge:

 

Input1: 1D array of elements (all elements)

Input2: 1D array of elements consisting of 2 elements which are allowed. 

 

Output: True if the two elements are in the array or if all the elements are equal

Output: False if the two elements are not in the array.

 

Input1: (1,1,2,1,1)

Input2: (1,2)

Output: True 

 

Input1: (1,1,2,1,3)

Input2: (1,2)

Output: False

 

Input1: (1,1,1,1,1)

Input2: (1,2)

Output: True

 

Best regards,

Thijs

 

 

 

0 Kudos
Message 4 of 8
(4,807 Views)
Solution
Accepted by topic author ThijsBoeree

Hi Thijs,

 

so you need to compare if each element of array1 is a member of array2:

check.png

Did I get this right?

 

Edit: the label of the output should be just "all elements of array are members of array2"

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 8
(4,803 Views)

Wow that's fast.

Thanks!

 

0 Kudos
Message 6 of 8
(4,793 Views)

Hi Thijs

 


Output: True if the two elements are in the array or if all the elements are equal


This is not clearly defined. What happens when array1 consist just of zeros and array2 contains [1, 2]? Giving your description you want output=TRUE (all elements are equal!) - my snippet will produce FALSE in this case...

 

Either redefine your question or modify my snippet! 😄

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 8
(4,788 Views)

Then my question was not right defined, because it works perfectly!

Regards

0 Kudos
Message 8 of 8
(4,776 Views)