minimun value in 2D array
75 次查看(过去 30 天)
显示 更早的评论
Can some body show me how to find minimum value in an image or 2D array along with its index. Regards
0 个评论
回答(2 个)
Kevin Schroeder
2021-11-9
I think you are looking for the minimum across both dimensions; something like this:
A = magic(5);
minValue = min(min(A));
[ind1, ind2] = find(A==minValue);
There are other ways to do this. For example, you can reshape the 2D array into a 1D array, and call min(), but then you have to convert the index back to the equivalent value for the 2D array using ind2sub(). I'm not sure wich is fast for large arrays, but the above method is more intuitive (in my opinion).
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!