Jump to content

Split array based on value


eberaud

Recommended Posts

I have an array that is already sorted. I want to find or write a VI that returns a subset of this array based on a minimum and a maximum values that I define.

 

For example, if the array contains [0,1,2,3,4,5] and I set min = 2.9 and max = 4.1, the function should return [3,4]. So far the only way I can think of is to take each element starting at index 0 and compare it to the minimum. When I find a value that is greater than the minimum, I start comparing each following element to the maximum. When a value is greater than the maximum, I can stop the execution and return what I have collected. Although this would work, it seems light-years away from being optimized... I can't find any LabVIEW or OpenG functions that does this.

 

I can't use the Search function since the minimum and maximum values might not match any element in the array...

 

Ideas appreciated :)

Link to comment

I looked at it, but because it was based on linear interpolation, I was afraid this would work only if the gap between each consecutive element is the same. If you confirm I was wrong, then great, I will use the Threshold function!

Link to comment

Nope, it works regardless of the gap size between elements-- array  =[1,10,100,1000,10000,100000] with min =99 and max=10001 works just as well, returning [100,1000,10000] . But be sure to do bounds checking on min and max, so an empty array is returned if they are out of bounds.

  • Like 1
Link to comment

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.