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.
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.
08-29-2011 01:26 PM
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
08-29-2011 01:49 PM
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.
08-29-2011 01:49 PM - edited 08-29-2011 01:53 PM
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).
08-29-2011 09:02 PM
the output array will be either decending or ascending. it is monotonic but not neccesary ascending.
08-29-2011 09:03 PM
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
08-29-2011 09:12 PM
I got it. I can use "search 1D array"...
Thanks,
Joyce
08-30-2011 02:20 AM
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.