Finding corners of a matrix inside a matrix.

조회 수: 6 (최근 30일)
Swapnil Rane
Swapnil Rane 2018년 2월 26일
댓글: Swapnil Rane 2018년 2월 26일
I have a matrix of size 50*80 which contains non-zero values in the center of matrix. for example-- I would like to extract the position of the corner elements in that matrix i.e position of (0,0,5,7) elements. Can anyone help me with the code?
A=[0 0 0 0 0 0 0 0 ;
0 0 0 2 4 5 0 0;
0 0 4 0 5 2 1 0;
0 0 5 8 7 6 7 0;
0 0 0 0 0 0 0 0;
end

채택된 답변

Birdman
Birdman 2018년 2월 26일
[r,c]=find(A~=0);
upperLeft=A(min(r),min(c))
lowerLeft=A(max(r),min(c))
upperRight=A(min(r),max(c))
lowerRight=A(max(r),max(c))
  댓글 수: 6
Stephen23
Stephen23 2018년 2월 26일
편집: Stephen23 2018년 2월 26일
upperLeft = [min(r),min(c)]
etc.
Swapnil Rane
Swapnil Rane 2018년 2월 26일
@KL and @Stephen Cobeldick, both of the code works for me.
Thank you, I really appreciate it.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by