11-17-2011 09:05 PM
I have a 2D array that looks like this:
1 1 1 1 1 1 1 1 1
1 1 1 1 0 1 1 1 1
1 1 0 0 0 0 0 1 1
1 0 0 0 0 0 0 0 1
1 1 0 0 0 0 0 1 1
1 1 1 1 0 1 1 1 1
1 1 1 1 1 1 1 1 1
It is actually 128 x 128. The above is a simplified version.
I want to find the min & max for both the x & y axis.
So I would get for the x-axis element 1 and 7 for min & max.
For the y axis, I would get elements 1 and 5 for max & min.
I know how to implement it using loops and searching each 1D array.
But there has got to be a better, more elegant way using existing analysis functions or other tricks.
Has anyone crossed this path before? with an elegant solution?
I tried a search, but I may not have used the appropriate terminology.
It's late and my brain gave up on me...
Thanks..
Solved! Go to Solution.
11-18-2011 12:35 AM - edited 11-18-2011 12:36 AM
You could try matrix math:
In your example, you know the all ones values are 7 for x and 9 for y. So, you just have to find the first non-7 or 9 from the front and back of the array.
11-18-2011 06:39 AM
This is great...
Why didn't I think of that??
Of course... I just look for the first column / row and last column/ row with a lower count..
Elegant indeed..
Thanks Matthew!
11-18-2011 02:06 PM
@Ray.R wrote:
This is great...
Why didn't I think of that??
Of course... I just look for the first column / row and last column/ row with a lower count..
Elegant indeed..
Thanks Matthew!
it really is pretty! And solved a simillar issue I R-G'd a year ago!
11-18-2011 03:08 PM
That's great!
11-21-2011 06:13 AM
Back in my machine code days I wrote a Comment
" It is the duty of every [machine code] programmer to use the instructions in some obscure and ingenious way to reduce execution time"
It seems nothing changes 😉
11-28-2011 03:43 PM - edited 11-28-2011 03:43 PM
The solution worked great. That's why I love sharing and learning on this forum.
😄
11-30-2011 01:18 AM - edited 11-30-2011 01:18 AM
@6829 wrote:
Back in my machine code days I wrote a Comment
" It is the duty of every [machine code] programmer to use the instructions in some obscure and ingenious way to reduce execution time"
It seems nothing changes 😉
After those days we "commented" our code with the greatest invevtion ever, the flair tip marker, Just draw a diagonal line across the punch card stack's edge and dataflow was enforced!!! Who else remembers when text languages like "Apple Basic" changed everything? how about formated text programing..... who's dealling with "turtle logo" today............... anyone?
Personally, I can't wait for LabVIEW 2031- with "undo, after dreaming into actuallaty, a universe were those rules would apply".