# LabVIEW

cancel
Showing results for
Search instead for
Did you mean:

Solved!
Go to solution

## Search in a array for a negative number and replace with a zero

Hello,

I want to search in a array  (double 64-bit)  for a negative number/s and replace it with a zero.

Br

Message 1 of 8
(4,704 Views)

## Re: Search in a array for a negative number and replace with a zero

I would use In Range and Coerce and coerce the array to between 0 and +Inf.

Message 2 of 8
(4,702 Views)

## Re: Search in a array for a negative number and replace with a zero

If you don't like that suggestion (I personally do), you can always use the same brute force method used in every other programming language.

Message 3 of 8
(4,648 Views)
Solution
Accepted by topic author LVdummies

## Re: Search in a array for a negative number and replace with a zero

Probably the quickest option in this case 😉

---
CLA
Message 4 of 8
(4,618 Views)

## Re: Search in a array for a negative number and replace with a zero

@thoult wrote:

Probably the quickest option in this case 😉

That's clever!

I ran a benchmark on that vs the coerce method and MaxMin is about 13x faster. Kudos!

Cheers

--------,       Unofficial Forum Rules and Guidelines                                           ,--------

'---   >The shortest distance between two nodes is a straight wire>   ---'

Message 5 of 8
(4,601 Views)

## Re: Search in a array for a negative number and replace with a zero

I was curious about the time too and found it was about 20x faster using the max min. I also found that the brute force method was about 6x faster than in range and coerce.

Message 6 of 8
(4,594 Views)

## Re: Search in a array for a negative number and replace with a zero

What the heck, I always assumed that VI must be faster than brute... Maybe it's best with some datatypes? Weird.

Cheers

--------,       Unofficial Forum Rules and Guidelines                                           ,--------

'---   >The shortest distance between two nodes is a straight wire>   ---'

Message 7 of 8
(4,584 Views)

## Re: Search in a array for a negative number and replace with a zero

Sorry, I meant that the brute force is about 2x faster than in range and coerce. And the advantage does appear to go away when using I32 datatype.

Message 8 of 8
(4,576 Views)