clear;clc;
A=[0 17 50;-12 40 3;5 -10 2;30 4 3]
[C,I]=max(A(:))
[m,n]=ind2sub(size(A),I)
运行结果:
A =
C =
I =
m =
n =
第二种:
clear;clc;
A=[0 17 50;-12 40 3;5 -10 2;30 4 3]
[M,I]=max(A)
[N,J]=max(M)
[I(J),J]
运行结果:
A =
M =
I =
N =
J =
ans =
第三种:
clear;clc;
A=[0 17 50;-12 40 3;5 -10 2;30 4 3]
N=max(max(A))
[r,c]=find(N==A)
运行结果:
A =
N =
r =
c =
MATLAB的矩阵元素顺序是按列排列的,也就是说index=9的一个元素在5*6的矩阵中处于(4,2)的位置,而在3*10的矩阵中处于(3,3)的位置。
ind2sub函数就是在指定矩阵尺寸(size)前提下将给定的index转化成行列形式
[I,J] = ind2sub(siz,IND) returns the matrices I and J containing the equivalent row and column subscripts corresponding to each linear index in the matrix IND for a matrix of size siz. siz is a 2-element vector, where siz(1) is the number of rows and siz(2) is the number of columns.(也是反映元素位置的)
For matrices, [I,J] = ind2sub(size(A),find(A>5)) returns the same values as [I,J] = find(A>5)
A=magic(4)
[Y_col,Ind_row]=max(A)%每列的{zd0}值及行号
[Y_row,Ind_col]=max(A')%每行的{zd0}值及列号
>> a=[1,2,3;4,5,6;7,4,2]
a =
>> a(:)
ans =
>> find(a>4)
ans =
>>
[i,j]=find(a>4)
i =
j =
已投稿到: |
|
---|