LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Remove negative values from array

 

Hi,

 

Just stumbled on this and thought I'd see if anyone could offer a more efficient solution?

 

I'd like to remove the negative values from an array (or values below any specified value?) Ive had a crack but maybe theres a better way? 

 

Any thoughts would be appreciated.

0 Kudos
Message 1 of 7
(5,020 Views)

Your vi can be simplified:

 

RemoveNegatives.png

 

Ben64

0 Kudos
Message 2 of 7
(5,015 Views)

Just to be different (if you really want to replace with NaN instead of removing the negative elements)

 

ReplaceWithNaN.png

0 Kudos
Message 3 of 7
(5,002 Views)

SDmanc wrote:

I'd like to remove the negative values from an array (or values below any specified value?) Ive had a crack but maybe theres a better way? 



As others have already said, your code does not "remove" anything, it just replaces certain values with NaN, keeping the array size constant. This is sufficient for waveform graphs where NaN's are not displayed.

 

Here's another cute solution 😄

 

 

If you really want to remove the negatives, shrinking the array accordingly, you need a little more code, of course.

 

Message 4 of 7
(4,994 Views)

I like that one too, fits nicely with the threshold.

 

ReplaceWithNaN_2.png

Message 5 of 7
(4,988 Views)

Hi,

 

Wow, thanks for the rapid responses.

 

What I want to do is replace the negative (or indeed above any set threshold) with a NaN so that when the waveform is plotted I can fit/filter/signal process etc.

 

But the potential issue is that I have to do this fairly rapidly as the data is from a DAQ card so the most efficient way is what I'm after. I'll try some the ways you all have suggested and I'll let you know which is best.

 

Thanks all, I really appreciate the time you've spent.

0 Kudos
Message 6 of 7
(4,970 Views)

SDmanc wrote:

What I want to do is replace the negative (or indeed above any set threshold) with a NaN so that when the waveform is plotted I can fit/filter/signal process etc.



Be aware that most fit/filter/process functions probably don't really like NaN and you might get very unexpected results.

The NaN method is mostly cosmetic and suitable for plotting, but not much more. 😉

0 Kudos
Message 7 of 7
(4,963 Views)