LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Average the nonzero elements in a vector

I have a double vector with 137 elements. The top and bottom of the vector are zero-filled. However, the number of useful data points and the size of the zero-filled range varies each time I look at the vector. I know how to use the mean function, but how can I remove all zeros in my vector prior to that?
0 Kudos
Message 1 of 9
(5,402 Views)
If you simply want to exclude all nonzero elements, you can do something simple as in this image.
 
(Sum all elements and divide by the number of nonzero elements)
 
If you only want to exclude the initial and final stretch of zeroes, but retain possible zeroes in the middle, things get very slighly more complex. 😉

Message Edited by altenbach on 05-10-2007 08:59 AM

Message 2 of 9
(5,397 Views)
Also, if your array is not an integer data type, you may need to use the In Range and Coerce function rather than Not Equal to Zero. Comparisons of floating point numbers to zero need to be approached cautiously because of finite representation of numbers in the computer.
0 Kudos
Message 3 of 9
(5,386 Views)
I was wondering what a "double vector" could possibly be. You're right, probably a "1D array of DBL" 😮
0 Kudos
Message 4 of 9
(5,379 Views)
You could do it in this way.
0 Kudos
Message 5 of 9
(5,354 Views)
Norbert, it does not really make a lot of sense to built an array if all you need is the sum of the element at the end. You could just keep the current sum in a shift register (see top of image). Also "array subset" is the right tool to take a subset, "split array" is overkill if you only need one of the outputs. 😉
 
Here are a few more variations to exclude elements close to zero. In the bottom code it only strips the head and tail, but averages all elements between the first and last zero element.

Message Edited by altenbach on 05-11-2007 08:27 AM

Download All
Message 6 of 9
(5,331 Views)
Any idea why my VI, which uses OPC to pull in an array of data, crashes LabVIEW when I hit the stop button? My paths are OK, since it works once in a while and has worked before. However, every time I want to stop execution and go to the block diagram, I crash labVIEW and sometimes Windows. Any and all suggestions are appreciated.
0 Kudos
Message 7 of 9
(5,298 Views)
Well, this probably has nothing to do with the code above. 😉
 
A crash should never happen in normal use, so someting is unexpected. Are you using some third-party DLL, for example?
 
Are you stopping with the stop button in the toolbar or with a boolean control on the front panel?
 
Other intersting information would be: Your OS, LabVIEW version, etc.
0 Kudos
Message 8 of 9
(5,288 Views)
Think you could help with my newest post?

I have to find the maximum value of certain ranges of array elements. Also trying to come up with a report that I can print.
0 Kudos
Message 9 of 9
(5,216 Views)