Jump to content
Sign in to follow this  
Manudelavega

Split array based on value

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 :)

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

OK perfect, thanks for the reminder about bound checking. I performed many tests and believe I have a final version of my subvi.

post-14511-0-65834000-1414695856_thumb.p

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

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