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

后端 未结 6 2036
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-29 06:54

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 ret

6条回答
  •  情书的邮戳
    2020-11-29 07:58

    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.

提交回复
热议问题