eberaud Posted October 29, 2014 Report Posted October 29, 2014 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 Quote
Popular Post MarkCG Posted October 30, 2014 Popular Post Report Posted October 30, 2014 (edited) "Threshhold 1D array" on the max and min, that gives the max and min indeces. Then grab the array subset based on that. It works only on sorted arrays, which you have. Edited October 30, 2014 by MarkCG 3 Quote
eberaud Posted October 30, 2014 Author Report Posted October 30, 2014 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! Quote
MarkCG Posted October 30, 2014 Report Posted October 30, 2014 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. 1 Quote
eberaud Posted October 30, 2014 Author Report Posted October 30, 2014 OK perfect, thanks for the reminder about bound checking. I performed many tests and believe I have a final version of my subvi. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.