maximum position of element in a matrix
10 次查看(过去 30 天)
显示 更早的评论
Hi I have a 1000x1000 matrix. I want to find the location and the value of the highest value in the matrix?
0 个评论
采纳的回答
Richard Brown
2012-4-11
Pretty straightforward - the only complicating factor is that max only works down one dimension at a time, so you either have to call it twice or turn the matrix temporarily into a vector. Probably easiest is this:
M = rand(1000);
[maxVal, idx] = max(M(:));
idx is a linear index. If you want the row/column index then
[i, j] = ind2sub(size(M), idx);
0 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!