Reputation: 338
For some "big data" processing. When plotted my data is sign wave like but with random peaks. (So imagine plotting the value of each matrix position against it's position)
I know how to find the peaks, but I need a way of then finding the value of local minima either side of the peaks and the position in the matrix. For example, if the data were:
3 2 1 0 1 2 3 7 -4 -5 -6 -5 -4 0
The function I need would return something like: min,loc = [0, -6; 4, 11]
Upvotes: 1
Views: 475
Reputation: 24169
MATLAB R2007a and newer have a function called findpeaks
(which requires the Signal Processing Toolbox). The syntax that you're looking for is
[pks,locs] = findpeaks(data)
Specifically,
>> [pks,locs] = findpeaks(-[3 2 1 0 1 2 3 7 -4 -5 -6 -5 -4 0]) % note it's "-[data]"
pks =
0 6
locs =
4 11
The minus is because we want the "valleys" and not "peaks", so make sure you don't forget to negate pks
afterwards.
Upvotes: 2
Reputation: 781
If you have access to R2017b or later, check out the islocalmax and islocalmin functions.
Upvotes: 2