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: 

Threshold 1D array

Hi, All,

 

I am trying to find the index of number 0 in a 1D array. I am using function "Threshold 1D array" as shown in the first attachment. The results are shown in the second attachment. The third element is 0 and I would expext the index should be 2, however, it is giving me 0. Why?

 

Thanks,

Joyce

Download All
0 Kudos
Message 1 of 7
(4,595 Views)

The Threshold 1D Array works on a monotonic array. Your array is not monotic. The first 2 values are 0.2 and 0.1. Both are larger than 0. The Help for that function explicitly details how this function works and why it won't work with your data.

 

Why is the output array like that? Why wouldn't 0 be first?

 

Note: in the VI you have the N terminal of the for loop wired and you have autoindexing on the array. Do one, or the other, not both. The for-loop will execute for whichever value is smaller if both methods are used.

0 Kudos
Message 2 of 7
(4,583 Views)

That function is for "non-descending" arrays.  Depending on the nature of your data you will have to negate or reverse your input, or try a different approach.

 

Edit:  "Montonic" does not necessarily imply ascending, only that there is not a turning point.  (Sorry if I am too anal, felt the twitch).

0 Kudos
Message 3 of 7
(4,582 Views)

the output array will be either decending or ascending. it is monotonic but not neccesary ascending.

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

can I do "abs" to the data? the data will be either descending or ascending, after taking absolute, the array will not be monotonic though.

what other approach can I try, I would love to know?

Thanks,

Joyce

0 Kudos
Message 5 of 7
(4,560 Views)

I got it. I can use "search 1D array"...

Thanks,

Joyce

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

No, search 1D array might not work because your array is DBL. All inherent problems comparing of floating point values apply. Threshold 1D array will give you a linearly interpolated value if the zero point is between two array elements while search 1D array will return nothing useful.

 

If the array is either ascending or descending, but not both, look at the initial slope and multiply the array by (-1) if it is negative before using threshold array.

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