LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to get the coordinates of the highest value element in an 2D array

Solved!
Go to solution

i am working on a project in which i am trying to find the coordinates of the highest element of that array ...please help 

0 Kudos
Message 1 of 11
(3,438 Views)

Use Array Max & Min.  I'm pretty sure it only accepts a 1D array though, so you will want to put it inside of a FOR loop.  Autoindex on the rows on the 2D array and then do some comparison to see if your new Max is greater than your old max.


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
0 Kudos
Message 2 of 11
(3,435 Views)

Reshape your array to a 1-D array and search for the max.  Now you have the coordinate you can do some basic math on to get back to the original row and column location.  (Remainder and quotient function would help here.)

0 Kudos
Message 3 of 11
(3,417 Views)
Solution
Accepted by rolfk

Let's stop this Rube in its tracks.

 

arraymax.png

 

indexes?  Nice one.  Indices is so old-fashioned these days...

Message 4 of 11
(3,405 Views)

Thanks for the replies but what exactly i asked was, for example if an 2D array  having 16 elements (i.e. 4*4)  and the greatest number of all the 16 elements is located [at lets say @ (3,2)] ,then my final out put should show me the column number and the row number 

0 Kudos
Message 5 of 11
(3,392 Views)

That is exactly what the snippet posted by Darin.K will provide. Try it.

 

Lynn

0 Kudos
Message 6 of 11
(3,385 Views)

@Darin.K wrote:

Let's stop this Rube in its tracks.

 

arraymax.png

 

indexes?  Nice one.  Indices is so old-fashioned these days...


I wasn't sure it would take a 2D array and didn't have a way to test it earlier.  Glad to see that it does.


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
0 Kudos
Message 7 of 11
(3,374 Views)

@Darin.K wrote:

 

indexes?  Nice one.  Indices is so old-fashioned these days...


Not that I claim this site to be fact, but it states both are correct, but one is more common in America vs other English

 

http://grammarist.com/usage/indexes-indices/

 

Personally I prefer Indices, but what ever.

0 Kudos
Message 8 of 11
(3,370 Views)

@Hooovahh wrote:

@Darin.K wrote:

 

indexes?  Nice one.  Indices is so old-fashioned these days...


Not that I claim this site to be fact, but it states both are correct, but one is more common in America vs other English

 

http://grammarist.com/usage/indexes-indices/

 

Personally I prefer Indices, but what ever.


Eh, it's just so they don't have to write "Index/Indices."  So much more efficient to put "Index(es)."

 

edit

I like "indices," myself.  It rolls off the tongue so much more smoothly.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 9 of 11
(3,350 Views)

I did the same thing as your question. My solution is:

- Reshape your 2D array to become a 1D array, for ex: your 2D is 4*4 and 1D reshaped is 1*16
- Use array Min and Max to find out Max value and Max index.

- Assume that your Max index is 10 = 4+4+2 so it means your coordinate of the Max value is (3,2)

Hope that my answer can help you.

0 Kudos
Message 10 of 11
(1,975 Views)