08-13-2009 04:24 PM
I've often run into this problem in LabVIEW, probably a result of my Matlab based thinking about arrays. Suppose I've got a 1-D array that consists of real numbers between 0 and 2 (e.g.):
1.3 0.1 0.7 1.9 1.4 1.5 1.5 0.8 1.3 0.3 1.4 1.4 0.1 0.6 0.1 0.2 1.6 1.6 1.4 0.6 1.9 0.1
and I want to know the mean of the subset of values that are greater than 0.5 and less than 1.2:
mean([0.7 0.8 0.6 0.6]) = 0.6750.
How can I return the subset of the array that meets the condition >0.5 & <1.2 ?
Solved! Go to Solution.
08-13-2009 04:36 PM
Hi James,
you can:
1) use a for loop to put all interesting values into a new array and calc the mean from that
2) sort your 1d array, then search for the first element fitting min criteria, then search for max criteria, then you know the indices to cut out from the big array...
3) use a for loop and call "Mean PtByPt" in a case structure...
Many ways lead to Rome
08-13-2009 09:20 PM - edited 08-13-2009 09:21 PM
For your example (values between 0.5 and 2) if you want this:
I would do something like this:
I just generated an array of 10 random numbers between 0.0 and 2.0
The next loop sorts through the data, by using 'In Range and Coerce'.
It then outputs the data that is in the selected range.
The last step is to take the average
I attached the VI if you would like to use the code.