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 to use threshold 1D array

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.

Download All
0 Kudos
Message 1 of 12
(4,491 Views)

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

Message 2 of 12
(4,475 Views)

@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.


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
Message 3 of 12
(4,471 Views)
0 Kudos
Message 4 of 12
(4,456 Views)

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


"Should be" isn't "Is" -Jay
0 Kudos
Message 5 of 12
(4,443 Views)

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!:

 

Thresholding.png

 

 

(Note that the correct term for the array requirements are "non-descending", so you need to make sure this is true.)

0 Kudos
Message 6 of 12
(4,429 Views)

@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 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 7 of 12
(4,426 Views)

@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"?)

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

@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

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 9 of 12
(4,415 Views)

@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". 😄

0 Kudos
Message 10 of 12
(4,407 Views)