Suppose I have an array, a = [2 5 4 7]
. What is the function returning the maximum value and its index?
For example, in my case that function should return 7 as the maximum value and 4 as the index.
max index(es) is the index for the first max value. If array is multidimensional, max index(es) is an array whose elements are the indexes for the first maximum value in array. min value is of the same data type and structure as the elements in array. min index(es) is the index for the first min value.
M = min( A ,[], dim ) returns the minimum element along dimension dim . For example, if A is a matrix, then min(A,[],2) is a column vector containing the minimum value of each row.
a = floor(rand(1,100000)*100); [val, idx] = max(a(20000:100000)); You want to use the max function here to find the maximum value rather than find.
The function is max
. To obtain the first maximum value you should do
[val, idx] = max(a);
val
is the maximum value and idx
is its index.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With