Local maxima in a matrix
이전 댓글 표시
I need to locate the peaks and valleys of numbers given in a large matrix. I need to compare a value in the matrix with the 8 surrounding values to determine if it is either a peak (maximum) or a valley (minimum). The matrix that I am using is 100X100 and the coordinates of the value will then need to be displayed in a table. For example: [3 6 2 5; 4 9 1 5; 7 3 5 4] has a peak of 9 at (2,2) and a valley of 1 at (3,2). Any ideas would be greatly appreciated.
채택된 답변
추가 답변 (1개)
Azzi Abdelmalek
2014년 11월 29일
편집: Azzi Abdelmalek
2014년 11월 29일
a=[3 6 2 5; 4 9 1 5; 7 3 5 4]
n=size(a);
[mina,idx1]=min(a(:))
[ii1,jj1]=ind2sub(n,idx1)
[maxa,idx2]=max(a(:))
[ii2,jj2]=ind2sub(n,idx2)
댓글 수: 1
Mohammad Abouali
2014년 11월 29일
편집: Mohammad Abouali
2014년 11월 29일
This is not the answer. This gives the global min/max. He is asking for local one.
카테고리
도움말 센터 및 File Exchange에서 Descriptive Statistics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!