Home > Mobile >  Matrix indexing in matlab
Matrix indexing in matlab

Time:12-15

I am trying to find index of lowest value of sub matrix mA from matrix A. z provides the index of lowest value in mA. How i can translate this index value of mA to the original matrix A

A = magic(11)
mA = A(3:5,5:7)
[~,rows] = min(mA)
[~,col] = min(min(mA))
z = [rows(col),col]

CodePudding user response:

A=randi([-10 10],11,11)
n1=3;n2=5;d1=3;d2=3;
mA=A(n1:n1 d1-1,n2:n2 d2-1)
[v1,q1]=min(mA(:))
[m1,m2]=ind2sub(size(mA),q1);
z=[n1 m1-1 n2 m2-1]
  • Related