From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I change all Inf elements in an array to a specific value?

Solved!
Go to solution

I would like to change all Inf elements in my array to -1. Basically, I am looking for something similar to the range and coerce function, except that I want all values above a certain value to be a specific negative value, rather than go to that value.

 

I could use a case structure and go through each element in the array, but I am hoping to find something more efficient.Any ideas?

0 Kudos
Message 1 of 12
(4,671 Views)

Let's clearify a little bit.  You start by saying all Inf values.  Then you say any values above a certain threshold.  Which is it?

 

If you are just looking for Inf, then I would use a While Loop with a Search 1D Array to find the Inf value, use Replace Array Subset to change the value in the found index to -1.  Stop the loop when the found index is -1 (not found).

 

If you want above a certain threshold, then you need a FOR loop to go through each element to check if it is above the threshold and then change the value.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 12
(4,653 Views)

@crossrulz wrote:

...

 

If you want above a certain threshold, then you need a FOR loop to go through each element to check if it is above the threshold and then change the value.


If you go with this option, don't forget to use an In Place Element structure. Sounds like a perfect use case.

0 Kudos
Message 3 of 12
(4,642 Views)

@westerman111 wrote:

I would like to change all Inf elements in my array to -1. Basically, I am looking for something similar to the range and coerce function, except that I want all values above a certain value to be a specific negative value, rather than go to that value.

 

I could use a case structure and go through each element in the array, but I am hoping to find something more efficient.Any ideas?


You can loop through the array and use the in range and coerce, but only check the "coerced" output, and if True, then Replace array subset with your specific value.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 12
(4,639 Views)

I would do that in this way.

 

Replace-Inf.png

 

If you want to check the values above a threshold just replace the "equal" with "greater or smaller" functions.

 


@Yamaeda wrote:

You can loop through the array and use the in range and coerce, but only check the "coerced" output, and if True, then Replace array subset with your specific value.

/Y


I don't understand this logic. sorry

-----

The best solution is the one you find it by yourself
0 Kudos
Message 5 of 12
(4,630 Views)

Personally, I would do something close to this (note: I did not really try to optimise anything)...

 

New Bitmap Image.png

Message 6 of 12
(4,625 Views)

P@Anand wrote:

I would do that in this way.

 

Replace-Inf.png

 


Here's a simpler version...


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 12
(4,613 Views)
Solution
Accepted by topic author westerman111

Hi,

 

How abt this?

 

234.PNG

 

 

Regards,
NitzZ

0 Kudos
Message 8 of 12
(4,611 Views)

@crossrulz wrote:

Here's a simpler version...


Agreed Architect but you didn't show the threshold logic. I would consider Don_Phillips's logic more simpler

 

-----

The best solution is the one you find it by yourself
0 Kudos
Message 9 of 12
(4,598 Views)

P@Anand wrote:

Agreed Architect but you didn't show the threshold logic. I would consider Don_Phillips's logic more simpler


Yours didn't have a threshold either.  But I fully agree that Don's is the simplest.  I'm curious what benchmarking would show...


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 12
(4,594 Views)