MatLabで2次元配列データの最大値検出

max関数を2回使う。
一度目のmaxで各列の最大値の値(maxvec)とその行の位置(rowvec)
二度目のmaxで行列全体の最大値(maxval)とその列の位置(column)
[maxvec, rowvec] = max(A);
[maxval, column] = max(maxvec);
A(rowvec(column),column)

>> A = magic(7)
A =
30 39 48 1 10 19 28
38 47 7 9 18 27 29
46 6 8 17 26 35 37
5 14 16 25 34 36 45
13 15 24 33 42 44 4
21 23 32 41 43 3 12
22 31 40 49 2 11 20

>> [maxvec,rowvec] = max(A)
maxvec =
46 47 48 49 43 44 45
rowvec =
3 2 1 7 6 5 4

>> [maxval,column]=max(maxvec)
maxval =
49
column =
4

>> A(rowvec(column),column)
ans =
49

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s