Minimum of a matrix with zeros

3 次查看(过去 30 天)
See in attachment the figure of my matrix. I can see that the number '340' is the lowest in my matrix (except for zero). I want to know the rownumber and columnnumber of 340 (ofcourse without going to check what the location of 340 is). Help?

采纳的回答

Image Analyst
Image Analyst 2014-12-27
A trick: how about setting 0's to inf:
m(m==0) = inf;
Then using min() to get the index of the min value. I'll let you do that since it's homework . Look at both return arguments of min().
  3 个评论
Star Strider
Star Strider 2014-12-27
The ‘maxNum’ value is the value of the result returned by the min funciton (the value of the minimum here), and ‘maxIndex’ is the index of the value in the array. Note that here, ‘Hoogste_US_matrix(:)’ has been converted to a column vector (the (:) subscript notation does that). You would have to use the ind2sub function to convert that index back to the appropriate matrix subscripts.
Image Analyst
Image Analyst 2014-12-27
I'd call them minValue instead of maxNum, and linearIndexOfMin instead of maxIndex. They are mins after all, not maxes.
minValue (what you called maxNum for some reason) is the minimum value in the array, which will no longer be zero since we replaced zeros with infinity.
The linear index is what number you'd get if you counted over to the location of the min by going down the columns from left to right. For example for a 3 by 5 matrix, these would be the linear indexes:
1 4 7 10 13
2 5 8 11 14
3 6 9 12 15
To get the actual row and column, you have to use ind2sub() as you already figured out.
If I helped you, please mark as "Accepted". Thanks in advance.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by