LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Searching for Ranges in an Array

Salutations,

I have taken the FFT power spectrum on data (continuously updating) and generated an array of the following format:

Hz       Mag
1            1.1
2            1.6
3            1.9
4            1.2
5            0.8

I want to search the Hz column array for a range of values, lets say 2-4 including 2 and 4.  This search will return an array of indices that are 1,2,3 in this example.  From this I will then index the Mag column array picking off the values that correspond to these indices: 1.6, 1.9, 1.2. I will then find the maximum value in this array: 1.9.  Then I want to plot this value along with the amount of times I've gone through this process: (1,1.9) for this example.

I was wondering if anyone had an efficient way of performing this process?  Because, what will probably happen is that instead of just finding the Hz values inbetween 2 and 4 inclusive, I'll be finding a bunch of ranges (2-4, 4.0001 - 6, 6.0001 - 8, 8.0001 - 10, etc...)

Thank you,
E. Smith
0 Kudos
Message 1 of 8
(4,828 Views)
You use "array subset" to get the subset, then "array min&max" to get the maximum of the subset. Just built an 1D array of the
 max values, the array index will give the number of times you've done it so you don't need a seperate column.
0 Kudos
Message 2 of 8
(4,813 Views)
Just in case the Hz is not just an index, but can be real, here's an example (7.1). The trick is that many functions are polymorphic, meaning they can accept different data types. Note how the array is wired into the In range and Boolean to 0,1 primitives.

___________________
Try to take over the world!
0 Kudos
Message 3 of 8
(4,805 Views)
Just in case the Hz is not just an index, but can be real, here's an example (7.1). The trick is that many functions are polymorphic, meaning they can accept different data types. Note how the array is wired into the In range and Boolean to 0,1 primitives.

___________________
Try to take over the world!
Message 4 of 8
(4,805 Views)
Altenbach,

Oh yes, I follow the array subset idea, it was my original intention.  However, is there an easy way to find the values that range from 2-4?  Or do I have to pass my array of Hertz values into a for loop and run through multiple comparisons to see if it fits into certain ranges?

IE:
Is 3 inbetween 2 and 4? -> Yes, then export to new array 1
Is 5 inbetween 2 and 4? -> No, then try the next possibility of... Is 5 inbetween 4 and 6?  Yes, then export to new array 2

And continue this process until I am done with all my values?
After this, I'll have multiple arrays that contain indices for values inbetween my selected ranges.
Then I'll use the array subset, and apply the max/min, and then build my final plot matrix?

Thank You,
E. Smith
0 Kudos
Message 5 of 8
(4,806 Views)

Did you see my example?


___________________
Try to take over the world!
0 Kudos
Message 6 of 8
(4,800 Views)
Sorry about that tst, i didn't notice that you attached a vi in that second post.  That seems to be a rather solid approach at doing this process, much appreciated.

Thank you,
E. Smith
0 Kudos
Message 7 of 8
(4,790 Views)

Can we make any assumptions about the array order? 

In your example the array is sorted, if that is the case then I suggest you use the Threshold 1-D array VI.  You can give it your Hz array and then the value you want to fine the corresponding index at.  You do that for both and it is then easy to grab the subset of data from the other array.  No need for a for loop etc.

See the attached VI

0 Kudos
Message 8 of 8
(4,789 Views)