08-08-2018 06:02 AM
Hello,
I want to use threshold array, but my array it's ordered from bigger values to smaller values. It's important to mantain the order of the array and calculate the fractional index, because this value is important in another part of the programe. Any suggestions?
I attached the result for different inputs, the output is always the same, equal to zero.
08-08-2018 07:16 AM - edited 08-08-2018 07:26 AM
Read the Help associated with the function.
Your array needs to be ordered low to high not high to low
Use reverse 1D array
Ken
08-08-2018 07:21 AM - edited 08-08-2018 07:21 AM
@IñigoP wrote: but my array it's ordered from bigger values to smaller values.
Use Reverse 1D Array before using the Threshold 1D Array. You can the subtract from then length-1 to get the index you want.
08-08-2018 09:20 AM
Thank you fellas, but I found another solution here:
https://forums.ni.com/t5/LabVIEW/quot-Threshold-1D-Array-quot-for-descending-data/td-p/515581/page/2
08-08-2018 12:58 PM - edited 08-08-2018 01:01 PM
Or, just negate the array and the threshold. Less math to deal with (Size- threshold) adds both an array size and a subtraction where the negate just flips sign bits
@IñigoP wrote:
Thank you fellas, but I found another solution here:
https://forums.ni.com/t5/LabVIEW/quot-Threshold-1D-Array-quot-for-descending-data/td-p/515581/page/2
And that example does not yield fractional indices- it yields integer indices after pos and neg going 0 transitions
08-08-2018 02:48 PM - edited 08-08-2018 02:56 PM
Instead of reversing, which potentially needs to move every single array element in memory, negate the array and search term instead. Better in-placeness (unless the compiler can do some magic with the reversal). Now you even get the correct index directly.
Works just fine!:
(Note that the correct term for the array requirements are "non-descending", so you need to make sure this is true.)
08-08-2018 02:55 PM
@altenbach wrote:
Instead of reversing, which potentially needs to move every single array element in memory, ...(unless the compiler can do some magic with the reversal). ...
I think I read Stephen saying the start location of the array is set to the end and the stride is set to "-1" ?
Ben
08-08-2018 02:58 PM - edited 08-08-2018 02:59 PM
@Ben wrote:
@altenbach wrote:
Instead of reversing, which potentially needs to move every single array element in memory, ...(unless the compiler can do some magic with the reversal). ...
I think I read Stephen saying the start location of the array is set to the end and the stride is set to "-1" ?
"Threshold array" does not have an input for "stride". (and who is "Stephen"?)
08-08-2018 03:04 PM
@altenbach wrote:
@Ben wrote:
@altenbach wrote:
Instead of reversing, which potentially needs to move every single array element in memory, ...(unless the compiler can do some magic with the reversal). ...
I think I read Stephen saying the start location of the array is set to the end and the stride is set to "-1" ?
"Threshold array" does not have an input for "stride". (and who is "Stephen"?)
The handle of the array keeps track of where it is in memory and the "stride" is used to adjust pointers into the array. By negating the "stride" the compile can reverse an array "in-place" and then the next node down the line can use the array but working backwards instead forward.
Stephen (AQ unless I spell his name wrong. Brain does not allow me to store correct spellings).
Ben
08-08-2018 03:28 PM - edited 08-08-2018 03:30 PM
@Ben wrote:
Stephen (AQ unless I spell his name wrong. Brain does not allow me to store correct spellings).
OK, I thought you were quoting somebody from this thread. 😉
Yes, for certain operations the compiler just flags that the array is reversed without making a new copy, but it is not clear if threshold array understands that flag (doubt it) or always expects a plain array. And we still have the problem that the returned fractional index is different from the index we want, i.e. the positions in the non-reversed array. I would go with "negate". 😄