LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Elegant way to find sudden changes in a 2-D array

Solved!
Go to solution

 

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

0 Kudos
Message 1 of 8
(2,757 Views)
Solution
Accepted by topic author Ray.R

You could try matrix math:

 

Matrix math.png

 

ScreenHunter_02 Nov. 18 01.35.jpg

 

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.

Message 2 of 8
(2,744 Views)

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!

0 Kudos
Message 3 of 8
(2,715 Views)

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


"Should be" isn't "Is" -Jay
0 Kudos
Message 4 of 8
(2,684 Views)

That's great!

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 5 of 8
(2,666 Views)

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 😉

0 Kudos
Message 6 of 8
(2,603 Views)

The solution worked great.  That's why I love sharing and learning on this forum.

 

😄

Message 7 of 8
(2,540 Views)

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


"Should be" isn't "Is" -Jay
0 Kudos
Message 8 of 8
(2,504 Views)