wuschelbeutel Posted September 3, 2012 Share Posted September 3, 2012 (edited) MsgBox(0, 'Max Index String value', _ArrayMaxIndex($Matr)) MsgBox(0, 'Max String value', _ArrayMax($Matr)) don't work. Edited September 3, 2012 by wuschelbeutel Link to comment Share on other sites More sharing options...
FireFox Posted September 3, 2012 Share Posted September 3, 2012 Hi, Take a look at the function UBound. Br, FireFox. Link to comment Share on other sites More sharing options...
wuschelbeutel Posted September 3, 2012 Author Share Posted September 3, 2012 I am familiar with this function but I dont know how it can help me get the max. Link to comment Share on other sites More sharing options...
FireFox Posted September 3, 2012 Share Posted September 3, 2012 (edited) I am familiar with this function but I dont know how it can help me get the max.What do you mean by the max, the max array index with no empty value ?Br, FireFox. Edited September 3, 2012 by FireFox Link to comment Share on other sites More sharing options...
wuschelbeutel Posted September 3, 2012 Author Share Posted September 3, 2012 (edited) The 2D-array contains numbers and I want to find the index of the one element that is the highest value of all elements in the matrix. E.g., A 2D matrix with rows [1,2,5], [4,2,6] [8, 2, 4] I want to have index (2,0) returned because its value is 8 Edited September 3, 2012 by wuschelbeutel Link to comment Share on other sites More sharing options...
FireFox Posted September 3, 2012 Share Posted September 3, 2012 Maybe this : Global $aMatrix[3][2] = [ _ [1.5, 2.3], _ [2.7, 5.54], _ [1.12, 5.55]] Global $iMatrixMaxFloatIndex = -1, $iMatrixMaxFloatSubIndex = -1, $iMatrixMaxFloat = 0 For $iIndex = 0 To UBound($aMatrix, 1) -1 For $iSubIndex = 0 To UBound($aMatrix, 2) -1 If $aMatrix[$iIndex][$iSubIndex] > $iMatrixMaxFloat Then $iMatrixMaxFloat = $aMatrix[$iIndex][$iSubIndex] $iMatrixMaxFloatIndex = $iIndex $iMatrixMaxFloatSubIndex = $iSubIndex EndIf Next Next ConsoleWrite("max float index: " & $iMatrixMaxFloatIndex & ", subindex: " & $iMatrixMaxFloatSubIndex & @CrLf) Br, FireFox. Link to comment Share on other sites More sharing options...
wuschelbeutel Posted September 4, 2012 Author Share Posted September 4, 2012 thanks Link to comment Share on other sites More sharing options...
UEZ Posted September 4, 2012 Share Posted September 4, 2012 (edited) Here a fast hack and not fully tested! expandcollapse popup#include <Array.au3> Global $aInt[3][3] = [[3,2,9], _ [4,2,6], _ [5, 9, 0]] $iMax = _ArrayMax2($aInt) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $iMax = ' & $iMax & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console $aFind = _ArrayFindAll2($aInt, $iMax) _ArrayDisplay($aFind) Func _ArrayMax2($array) Local $iMax = -1, $i Local $iUB = UBound($array, 2) If $iUB Then For $i = 0 To $iUB - 1 _ArraySort($array, 1, 0, 0, $i) If $iMax < $array[0][$i] Then $iMax = $array[0][$i] Next Return $iMax Else _ArraySort($array, 1) Return $array[0] EndIf EndFunc Func _ArrayFindAll2($array, $Val) Local $aRes, $x, $y, $i Local $iUB = UBound($array) Local $iUB2 = UBound($array, 2) If $iUB2 Then Dim $aRes[$iUB][2] For $y = 0 To $iUB - 1 For $x = 0 To $iUB2 - 1 If $array[$x][$y] = $Val Then $aRes[$i][0] = $x $aRes[$i][1] = $y $i += 1 EndIf Next Next If $i Then ReDim $aRes[$i][2] Return $aRes EndIf Return SetError(1, 0, 0) Else $aRes = _ArrayFindAll($array, $Val) Return $aRes EndIf EndFunc It searches for the max value in the array and displays the coordinate where the values have been found (zero based -> 1st row x and 2nd row y coordinate). Br, UEZ Edited September 4, 2012 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now