LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Extracting array index with values greater than zero

Solved!
Go to solution

How is it possible to extract the indices of elements greater than zero in a 2D array ?

 Example:

Array :

0  12  11  33   0

1  0     0    0    0

2  99   0    9    0

 

Need to get the array indices of 12,11,33 and so on...

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 1 of 13
(7,440 Views)
Solution
Accepted by Nghtcrwlr

Nghtcrwlr,

 

Attached the first thing that came to mind.

  

Dan

Message 2 of 13
(7,426 Views)
Note: ignore the default values I saved... I saved the default values between modifying the input array and running the vi 🙂
0 Kudos
Message 3 of 13
(7,425 Views)

Just nest one for loop inside another.  With automatic indexing, it's easy to compare your search value against each element in the array.  I ended up using a cluster array and shift registers to store the locations when you get a match so as to handle the case where there are multiple matches...

 

 

Message 4 of 13
(7,423 Views)

Aww... Mcdan beat me to it by one minute - and with a better solution! 🙂

 

The build array vis can slow things down, but I still use them for smaller arrays.

0 Kudos
Message 5 of 13
(7,420 Views)

Jason,

 

I'm using insert into array, and given that I start with an empty array, it will cause  memory allocation as well.  To avoid this for this problem, we'd either have to pre-allocate an array that is equal in size to the input array, or basically run our search twice... the first time to count the nonzero entries, and the second to add their values to an array we allocated after counting nonzero entries.  For small data sets, this seems like too much work!

 

Dan

0 Kudos
Message 6 of 13
(7,417 Views)

HHello Everyone...

thanks...i was trying to do with max min  function,comparing it with 0 and doin a lot bulky...

What if the input array is a complex number array. Then the comparison function wont work. what can be done then?

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 7 of 13
(7,393 Views)

I haven't had to use complex numbers in Labview... can't remember if there are any specific functions to handle this.  If not, I'd recommend converting everything to strings and doing it that way.

0 Kudos
Message 8 of 13
(7,381 Views)

If you just want to know if a complex number's absolute value is > 0 just use the absolute value function before doing the >0 comparison.

 

Hope this helps,

Daniel

 

Message 9 of 13
(7,373 Views)

converting to strings???

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 10 of 13
(7,356 Views)