How can I find the value of vector for the local maximum and the nearest local minima (befor and after maximum value)?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Image Analyst
il 8 Giu 2013
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 Commenti
Image Analyst
il 8 Giu 2013
Modificato: Image Analyst
il 8 Giu 2013
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)
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!