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.
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.
05-28-2014 03:19 AM
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
Solved! Go to Solution.
05-28-2014 03:31 AM
I got this thus far...?
But maybe there is something more simple?
regards,
Thijs
05-28-2014 03:34 AM - edited 05-28-2014 03:39 AM
Hi Thijs,
you need to compare one element of the array with the remaining ones:
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…
😄
05-28-2014 03:52 AM
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
05-28-2014 03:57 AM - edited 05-28-2014 04:03 AM
05-28-2014 04:03 AM
Wow that's fast.
Thanks!
05-28-2014 04:07 AM - edited 05-28-2014 04:07 AM
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! 😄
05-28-2014 05:32 AM
Then my question was not right defined, because it works perfectly!
Regards