Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find the maximum value and its index in array in MATLAB?

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.

like image 311
Yuseferi Avatar asked Nov 23 '12 14:11

Yuseferi


People also ask

What is the maximum and minimum index of an array?

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.

How do you find the minimum index in MATLAB?

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.

How do you find the maximum value for a range in MATLAB?

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.


1 Answers

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.

like image 168
Acorbe Avatar answered Sep 19 '22 15:09

Acorbe