Address position in array

Y

Yankee1423

Say I have a 5 by 5 array. I would like to find the highest value in
each column of that array and also its position. For example in the
following example I'd like to get return the following data:


0, 2, 3, 4, 1
2, 3, 9, 10, 3
3, 4, 6, 7, 8
3, 6, 4, 2, 1
6, 8, 0, 3, 4

6 (5,1)
8 (5,2)
9 (2,3)
10 (2,4)
8 (3,5)

I am able to find the 6, 8, 9, 10, 8 number with a sort function but
can't seem to get the position. Here is the sort function I'm using:
--------------------------------------------------------
Sub Sort(Arr() As Double, first As Integer, last As Integer)
Dim I As Integer
Dim J As Integer
Dim SwapStr As Double
Dim Cont As Double
Dim K As Integer


For K = 1 To 5
For I = first To last - 1
For J = I + 1 To last
If Arr(I, K) > Arr(J, K) Then
SwapStr = Arr(I, K)

Arr(I, K) = Arr(J, K)
Arr(J, K) = SwapStr
End If
Next J
Next I

Next K
 
M

Marco Pagliero

Yankee1423 said:
Say I have a 5 by 5 array. I would like to find the highest value in
each column of that array and also its position. For example in the
following example I'd like to get return the following data:

0, 2, 3, 4, 1
2, 3, 9, 10, 3
3, 4, 6, 7, 8
3, 6, 4, 2, 1
6, 8, 0, 3, 4

6 (5,1)
8 (5,2)
9 (2,3)
10 (2,4)
8 (3,5)

I am able to find the 6, 8, 9, 10, 8 number with a sort function but
can't seem to get the position. Here is the sort function I'm using:

I don't understand why you'd need to sort the array at all. If I need
to know for every column the highest value and its position I do it
like this:

Dim Result(MaxCol, 1)
For Col = 1 To MaxCol
For Row = first To last
If Arr(Col, Row) > Result(Col, 0) Then
Result(Col, 0) = Arr(Col, Row)
Result(Col, 1) = Row
end if
Next Row
Next Col

At end I have in
Result(1,0) the highest value in the 1st column and in Result(1,1) its
position,
Result(2,0) the highest value in the 2nd column and in Result(2,1) its
position,
Result(3,0) the highest value in the 3rd column and in Result(3,1) its
position,
....

Greetings
Marco P
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top