フィルターのクリア

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)
Ashraf Afana
Ashraf Afana 2013 年 6 月 9 日
Thanks a lot, it works perfectly.
cheers

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by