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

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

    This will return the maximum value in a matrix

    max(M1(:))
    

    This will return the row and the column of that value

    [x,y]=ind2sub(size(M1),max(M1(:)))
    

    For minimum just swap the word max with min and that's all.

提交回复
热议问题