How to get MATLAB to display the index of the minimum value in a 2D array?

后端 未结 5 2028
余生分开走
余生分开走 2020-12-28 17:21

I\'m trying to write a script in MATLAB that finds the location of the minimum value of a 2D array of numbers. I am certain there is only 1 minimum in this array, so having

5条回答
  •  旧巷少年郎
    2020-12-28 17:33

    As an alternative version, combine min to get the minimum value and find to return the index, if you've already calculated the minimum then just use find.

    >> a=magic(30);
    >> [r,c]=find(a==min(min(a)))
    
    r =
         1
    c =
         8
    

    Or depending on how you want to use the location information you may want to define it with a logical array instead, in which case logical addressing can be used to give you a truth table.

    >> a=magic(30);
    >> locn=(a==min(min(a)));
    

提交回复
热议问题