LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to eliminate or remove zeros from 1D array

Solved!
Go to solution

Hi Josh,

 

- use a wire branch of your input array connected to the FOR loop border to enable autoindexing instead of ArraySize connected to the N terminal

- use the conditional break of the FOR loop to prematurely end the loop when no zeros are found! Why keep searching N-1 elements, when the N-th element didn't yield in a "found" zero?

 

Or, even more "Simple, quick, easy": use Christian's suggestion with a conditional output tunnel!

And keep in mind: comparing floats for equality may result in unexpected results…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 11 of 13
(1,379 Views)

First

 


@JoshStenzler wrote:

 

Simple, quick, easy.


Yes but prone to unexpected outputs as this thread has been discussing.  Floating point precision equal comparison kills programs.   Well sorta, not really it just does what you ask, and being unaware of the consequences could have issues.  Be sure and read up on the topic, and understand the data you are getting, and you might be fine.

0 Kudos
Message 12 of 13
(1,366 Views)

@JoshStenzler wrote:

Simple, quick, easy.


In addition to what has been said already....

 

Very, very inefficient. First of all, constantly resizing an array in a tight loop causes many expensive memory allocations.

You algorithm gets astronomically slow for large arrays O(NxN), because you start searching from the beginning over and over. You only need to start searching from where you left off, there is a start index input for that reason. Currently, you are inspecting the first element N times.

 

Back to the drawing board! Currently it is "simplistic, slow, and inefficient".

Message 13 of 13
(1,344 Views)