How can I find the value of vector for the local maximum and the nearest local minima (befor and after maximum value)?
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi,
I have a vector array (e.g. 2 12 4 6 9 4 2 5 10 19 7 5 3 7 4) and I need to define the part of the vector with local maximum value and the neighbouring minima, located to the left and right of the maximum). In the above example it should be [2 5 10 19 7 5 3].how can I code that in matlab? any help please..
Thanks,
댓글 수: 0
채택된 답변
Image Analyst
2013년 6월 8일
Why does the 12 at element 2 not qualify as a local max? Do you have the Image Processing Toolbox, try imregionalmax(). If you have the Signal Processing Toolbox, try findpeaks on the signal and the inverted signal.
댓글 수: 3
Image Analyst
2013년 6월 8일
편집: Image Analyst
2013년 6월 8일
Try this:
m = [2 12 4 6 9 4 2 5 10 19 7 5 3 7 4]
regMax = imregionalmax(m)
regMin = imregionalmin(m)
% Find the 3rd peak
index3 = find(regMax, 3, 'first')
index3 = index3(end)
% Find out the mins on either side of that.
% Find the min locations
minLocations = find(regMin)-index3
% Find where the first one goes positive (right side)
rightIndex = minLocations(find(minLocations>0, 1, 'first'))+index3
% Get the left side:
leftIndex = minLocations(find(minLocations<=0, 1, 'last'))+index3
% Get the stretch from left min to right min on either side of the 19.
stretch = m(leftIndex:rightIndex)
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!