Write MatLab commands to find the index of the max value in the bold area of A

1 次查看(过去 30 天)
I also need to find find the index of the maximum value in the bold area of A.
A>>
7.24 0.80 *7.31* *9.24* *3.09*
1.06 0.06 *8.97* *1.37* *0.55*
8.67 8.88 *9.92* *0.71* *0.90*
3.45 9.01 *9.15* *4.80* *2.29*
4.56 5.16 *5.33* *7.10* *7.61*
1.16 0.64 *0.08* *8.76* *8.06*
8.96 6.23 *9.96* *6.93* *7.71*
8.15 6.84 *6.95* *1.88* *7.36*
4.75 1.54 0.28 3.10 9.04
2.95 8.42 2.33 1.38 4.39
2.28 4.74 7.54 7.94 3.73
7.48 3.01 7.61 8.38 4.85
I tried to do B=find(A(1:8,3:5>2 & 1:8,3:5<=6)) but I not sure if the command is the right one here to find the values in the bold area and [m,n]=max(max(A(1:8,3:5))

回答(2 个)

Walter Roberson
Walter Roberson 2012-11-30
T = A(1:8, 3:5);
[m, idx] = max(T(:));
[r, c] = idx2sub(size(T), idx);
B = [r, c+2];
This would leave B in [row column] format relative to A. You weren't clear as to the form of the index you wanted, and you weren't clear if you wanted the index within the sub-array or within all of A.
  3 个评论
Walter Roberson
Walter Roberson 2012-11-30
That's what my code calculates, in row and column form. If you want it in scalar index form then probably the easiest way would be to use
B = sub2idx(size(A), r, c);

请先登录,再进行评论。


Andrei Bobrov
Andrei Bobrov 2012-11-30
编辑:Andrei Bobrov 2012-11-30
variant
B = -inf(size(A));
B(1:8,3:5) = A(1:8,3:5);
[m,n] = find(abs(B - max(B(:))) < eps(100));

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by