LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Search and Erase Element from Array

Try something like this...

 

Message 11 of 23
(1,910 Views)

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 ..

0 Kudos
Message 12 of 23
(1,886 Views)

@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

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 13 of 23
(1,879 Views)

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 

0 Kudos
Message 14 of 23
(1,865 Views)

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?

0 Kudos
Message 15 of 23
(1,832 Views)

Thank you  for the warnings and help. This is a very creative way of solving my  problem. 

 

 

ps sorry for late reply ... been away

0 Kudos
Message 16 of 23
(1,757 Views)

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:

node.jpg

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.

Message 17 of 23
(1,643 Views)

@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)

0 Kudos
Message 18 of 23
(168 Views)

Ok.  I'll bite:

an0n.png

0 Kudos
Message 19 of 23
(159 Views)

@paul_a_cardinale wrote:

Ok.  I'll bite:

an0n.png


 

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.

 

removeBadStuff.gif

(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.)

0 Kudos
Message 20 of 23
(143 Views)