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

后端 未结 6 2025
爱一瞬间的悲伤
爱一瞬间的悲伤 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:45

    In case of a 2D array (matrix), you can use:

    [val, idx] = max(A, [], 2);
    

    The idx part will contain the column number of containing the max element of each row.

提交回复
热议问题