How do I find the values of local maximas between certain points on a graph using the "findpeaks" function?
1 view (last 30 days)
Show older comments
Say I used the "findpeaks" function to find the local maximas in my data as follows which produces the following graph:
t = 0:0.05:25; % values for time
y = cos(3*t);
[pks,locs] = findpeaks(y);
plot(t,y,t(locs),pks,'rv','MarkerFaceColor','r');
grid on; title('Position -vs- Time'); xlabel('Time'); ylabel('Position');
Obviously in this instance, all the local maximas would have the same values for position. However, for the sake of argument, say I only wanted to find the values for the position of the local maximas between time = 10 and time = 25, how would I go about doing this without changing the values for 't' which I initially used to plot the graph?
Any help appreciated!
0 Comments
Accepted Answer
Azzi Abdelmalek
on 27 Oct 2013
t = 0:0.05:25; % values for time
y = cos(3*t);
idx=find(t>=10 & t<=20);
[pks,locs] = findpeaks(y(idx));
locs=idx(locs)
0 Comments
More Answers (0)
See Also
Categories
Find more on Parametric Spectral Estimation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!