09-15-2014 08:17 AM
How to eliminate or remove zeros from 1D array. Let say I have 1D array having foolowing elements
"0 0 0 0 0 4 0 0 9 0 0 1 4 0 0 0 0 0 0 0 0 10 9 0 0"
So after removing or eliminating zeros it will become as follow
"4 9 1 4 10 9"
So can any body guide me how can I do that? See attached Image for details.
Thanks
JK
Solved! Go to Solution.
09-15-2014 08:20 AM
I am sure this post could help you.
09-15-2014 08:29 AM - edited 09-15-2014 08:35 AM
P@Anand wrote:
I am sure this post could help you.
No, that's a bad and inefficient example. 9 years ago we discussed that in detail, and this VI (posted here) contains two possible solutions. If the array is large, you should use the lower solution. (read the entire thread!)
If you have a newer LabVIEW version (2012+), you can also use a conditional indexing tunnel for an even simpler solution. (see image)
09-15-2014 09:23 AM - edited 09-15-2014 09:23 AM
The simple solution I use is the OpenG Filter 1D Array function. It is not as efficient as other methods, but does have other features, and it is already written. For huge amounts of data I would do something else, but for simple data it works fine.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
09-15-2014 09:44 AM
thanks it is perfect.
07-08-2015 01:44 PM
Here are 2 example .vi's I made based on altenbach's removeZeroes.png in this discussion thread:
07-08-2015 04:11 PM
@hchiam wrote:
Here are 2 example .vi's I made based on @altenbach's removeZeroes.png in this discussion thread:
It seems pretty pointless to post those because no new useful information is given.
07-08-2015 05:49 PM - edited 07-08-2015 05:52 PM
altenbach a écrit :
@hchiam wrote:
Here are 2 example .vi's I made based on @altenbach's removeZeroes.png in this discussion thread:
It seems pretty pointless to post those because no new useful information is given.
- Currently, only the input is defined in the connector pane, making them useless as subVIs.
- unlike my example using integers, an "=0", like any "equal" comparison, is potentially dangerous with DBLs.
- Reshaping a 2D array to 1D before removing zeroes is pretty pointless because a 2D output cannot be recovered. A more interesting scenario would be to remove some columns or rows (e.g. that are all zeroes) from a 2D array.
- You should also clean up the front panel, e.g. properly zero the upper left corner, make the controls/indicators nicely labeled, sized and arranged, and maybe even add scrollbars to the arrays.
Thank you for those comments.
Hopefully if someone is looking for this, they can just use or play with an example subVI (granted that they know how to plug things in for their context). I was hoping to post a subVI people could put to direct use.
07-09-2015 07:13 AM - edited 07-09-2015 07:13 AM
hchiam wrote:
- I'm not sure about what you mean exactly with "=0" being "potentially dangerous with DBLs". I'm guessing you had a certain case scenario in mind. Although the subVI's seem to work fine within my larger program and situation, my situation may not generalize with regards to this point.
He was refering to the fact that for a double to be equal to another double, 64 bits that represent the double need to be equal to another 64 bits. And with fractional precision this can be a bit difficult. Is 0.0 equal to 0.0000000000000001? No but they both look the same on a graph and you may wonder why your filter isn't removing all the zeros. This might not be the best explaination but here is on of many threads talking about floating point comparision.
http://forums.ni.com/t5/LabVIEW/Bug-Two-Doubles-not-detected-as-equal-v8-6/td-p/1066548
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
03-31-2016 04:24 PM
I found this simple "for loop" worked the best for me.
Search the array for the zeroes, then delete them from the array and repeat the number of cells in the array.
Simple, quick, easy.