How to find the maximum value of an array in Matlab and Octave
To find the maximum value of the elements of a vector, use the function max()
max(v)
The v parameter is a vector.
The max() command returns the element with the maximum value.
Note. The max () function can be used to search for the maximum value in numeric or alphanumeric elements. If the vector has alphanumeric elements, the function finds the maximum value of the ASCII code of the characters.
Examples
Example 1
Create a numeric array
>> v=[5; 1; 4; 7; 3]
To find the maximum value use the max command
>> max(v)
ans = 7
In this case the maximum value of the elements of the vector is 7
Example 2
Create an array with alphanumeric elements
>> w=['g'; 'b'; 'd'; 'z'; 'k']
Again you can find the maximum value using the max command
>> max(w)
ans = 122
In this case the max () command finds the character with the highest ASCII code.
The command output is 122. It is the ASCII code of the character z.
>> char(122)
ans = z