08-11-2022 03:15 PM - edited 08-11-2022 03:51 PM
I want to go through an 1D array with unknown number of elements. The goal is to check if every 15 consecutive elements are the same; to determine if there any elements that are the same within 15 consecutive intervals. The output should return a boolean. My thought process is to divide the array so each 15 element subset can be gathered and then compare each element to the first using an equal comparison within each subset. I'm struggling getting each 15 element subset. Please help in any way with the entire process or advice on better methods.
08-11-2022 04:06 PM
@qujeoiandlkamfpoqwm wrote:
I want to go through an 1D array with unknown number of elements. The goal is to check if every 15 consecutive elements are the same; to determine if there any elements that are the same within 15 consecutive intervals. The output should return a boolean. My thought process is to divide the array so each 15 element subset can be gathered and then compare each element to the first using an equal comparison within each subset. I'm struggling getting each 15 element subset. Please help in any way with the entire process or advice on better methods.
Hello, check this out. You might have to figure out what happens when you get an array that is not evenly divisible by 15, is that a T or F case?
08-11-2022 04:13 PM
08-12-2022 10:31 AM - edited 08-12-2022 10:41 AM
I ran the Vi, but I can only see the last subset which has less than 15 elements since that is the remainder. I added a probe in between the array subset and delete from array functions. Your solution only checks the last subset. If the another subset has 15 consecutive elements that are the same it does not return true. I checked this by making the first 15 elements the same. It returned true when I removed array size and made the loop iterate once since there was only one subset. However, when I added array size, the result would be false even though the first 15 elements were the same. Also, And Array Elements cannot be used outside of the loop because it only returns true if all subsets are true. I need it to return true if at least one is true since that would be mean there was in instance in the array where there were 15 consecutive elements of the same value.
08-12-2022 10:33 AM - edited 08-12-2022 10:34 AM
08-12-2022 12:29 PM
It is not clear if you want to take a sliding window and check each subset (0..14, 1..15, 2..16, etc.) or only intervals (0..14, 15..29, 30..44, etc.).
You also did not specify the datatype (integer, string, boolean, etc.). Be aware that checking e.g. DBL for equality is very dangerous and often not recommended, depending on where the data comes from.
@qujeoiandlkamfpoqwm wrote:
... determine if there any elements that are the same within 15 consecutive intervals.
If they are the same within 15 consecutive 15 element intervals, that's the same as saying they are the same for ~15+15 or 15x15 consecutive elements, depending on how the problem is defined.
What kind of result do you want?
Just a TRUE/FALSE that there is at least one subset that fits the criterium?
Do all subsets need to have the same value or can each subset contain a different value across its elements?
A list of all subset positions that match?
In any case, all possible solutions would be trivially simple. Easiest would be if you could attach a simple VI that contains a typical input as diagram constant and a description of the expected result.
08-12-2022 12:53 PM - edited 08-12-2022 12:55 PM
@qujeoiandlkamfpoqwm wrote:
Also, And Array Elements cannot be used outside of the loop because it only returns true if all subsets are true.
So use "OR array elements" instead. (You never really specified what kind of output you want. 😄 )
See if this can give you some ideas....
"Reshape array" creates a 2D array with 15 columns and N/15 rows, padded with zeroes if the size is not divisible (adjust if needed).
For each subset, if min=max, all elements are the same, right?
08-12-2022 01:34 PM
Could you add a set of sample data showing what you'd like to result in a "True" value, and some sample data that results in a False value? I'm a little unclear about your requirement. It also sounds like you want a boolean for EACH group of 15, not EVERY group of 15 (like in your title).
Sample data would help a lot- we can get you going in a few minutes if you can get us that.
08-15-2022 10:13 AM
If there were 100 elements in an 1D array. If each subset of 15 elements starting from the beginning had 15 of the same values then the result would be true. For example, there was one subset that had all elements be of value 10. The below solution from someone else that commented was mostly what I wanted. I just had to change the And Array Elements function to Or Array Elements.
08-15-2022 10:39 AM - edited 08-15-2022 10:45 AM
@qujeoiandlkamfpoqwm wrote:
If there were 100 elements in an 1D array. If each subset of 15 elements starting from the beginning had 15 of the same values then the result would be true. For example, there was one subset that had all elements be of value 10. The below solution from someone else that commented was mostly what I wanted. I just had to change the And Array Elements function to Or Array Elements.
100 is not divisible by 15 without remainder, meaning your last slice might either be missing or not contain 15 elements, depending on the rounding of the division result. You probably need to make much more rigid specifications for predictable results.
Instead of slicing and dicing arrays and doing 14 comparisons resulting in a boolean array with 14 booleans to be combined a nanosecond later, you can also compare that array min&max as in my example (if min=max, all elements are the same, right?)