10-05-2010 04:23 PM - edited 10-05-2010 04:23 PM
10-06-2010 08:25 AM
Thanks a lot. Will the example you just give me cause problems? The arrays I will be using will have any where from 10 to 2400 elements.
Thank for the help ..
10-06-2010 08:43 AM
@sticyfinger wrote:
Thanks a lot. Will the example you just give me cause problems? The arrays I will be using will have any where from 10 to 2400 elements.
Thank for the help ..
What kind of problems are you envisioning?
Christian is one of our most experienced contributors and his examples are always top-notch.
So what is your concern?
Ben
10-06-2010 09:07 AM
Before he posted the solution he said “ Simply find the first and last nonzero element and then take the array subset of all data in-between.
ALso note that comparisons of DBL data with zero might cause problems. “
Just wanted to know if that example would cause any problems
10-06-2010 11:46 AM
A comparison with zero using DBL can be problematic if the zeros are not exactly zeroes, e.g. because they are derived from a calculation.
If all are true zeroes, you won't have a problem. (See also). Where does the data come from?
10-20-2010 10:56 AM
Thank you for the warnings and help. This is a very creative way of solving my problem.
ps sorry for late reply ... been away
03-29-2011 11:47 AM
I had the same problem, wanting to remove 0s and NANs from an array. Eventually I succumbed to using a MathScript node (corresponding VI attached), because the block diagram solutions look complicated (perhaps just low-level) for such a simple concept:
I'm unsure how LabVIEW manages memory in the MathScript node, so there may be a better way to write it. It works and it's simple.
Some posts here have mentioned a problem with zeros that aren't quite zeros, such as from real world measurements or calculations with rounding errors. To cover these near-zero numbers in the above script,use the following instead:
tolerance = eps*2;
indexes_to_remove = abs(array) < tolerance | isnan(array);
Set tolerance to suit your needs. The variable named `eps` is built-in to LabVIEW as the machine's precision, which I think is the smallest number it can represent with a double.
01-17-2025 12:45 PM - edited 01-17-2025 12:46 PM
@Artybear wrote:
I had the same problem, wanting to remove 0s and NANs from an array. Eventually I succumbed to using a MathScript node
The use of Mathscript is no longer recommended and will probably cause a huge performance penalty in this case. For any graphical LabVIEW programmer, your code is incomprehensible and even mild dyslexia would interfere even more.
There is nothing complicated about my solution, which operates fully in-place and is trivially simple. It can easily be modified for any other condition and if you need this often, turn it into a subVI.
(note that e.g. delete from array should never be used in a tight loop)
01-17-2025 01:20 PM
Ok. I'll bite:
01-17-2025 02:23 PM
@paul_a_cardinale wrote:
Ok. I'll bite:
Quite a bit more effort compared to my ancient example above, because if e.g. the array has 1M NaNs or zeroes, you do 1M replace operations while my code does zero for the same result.
(The change between index array and autoindexing is probably irrelevant. I have fewer tunnels at the cost of a size detection. I am sure the compiler can optimize both.)