Minimum of a matrix with zeros
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sam
am 27 Dez. 2014
Kommentiert: Image Analyst
am 27 Dez. 2014
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?
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 27 Dez. 2014
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 Kommentare
Star Strider
am 27 Dez. 2014
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
am 27 Dez. 2014
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!