03-18-2009 06:01 AM
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...
Solved! Go to Solution.
03-18-2009 06:40 AM
Nghtcrwlr,
Attached the first thing that came to mind.
Dan
03-18-2009 06:43 AM
03-18-2009 06:44 AM
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...
03-18-2009 06:46 AM
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.
03-18-2009 06:54 AM
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
03-18-2009 07:27 AM
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?
03-18-2009 07:51 AM
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.
03-18-2009 07:58 AM
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
03-18-2009 08:42 AM
converting to strings???