How can I find the value of vector for the local maximum and the nearest local minima (befor and after maximum value)?

1 次查看(过去 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,

采纳的回答

Image Analyst
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
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!

Translated by