How do I find the (x,y) coordinates of the peaks and valleys of a graph?

P
Paxton · Jan 6, 2021 · 2.1K views
Question
I am new to Matlab and I am not sure how to find the coordinates of the peaks or valleys of my graph. After looking online, I tried using findpeaks() which did give me the y-values of the local maxima of my function ((e^(−at))*cos(2πft), where t is time and a and f are constants). However, I have not been able to find the corresponding x-values (and findpeaks() omits a local max at the y-intercept). I am also not at all sure how to find the coordinates for the valleys (minima or "troughs").
Expert Answer
Profile picture of John Michell
John Michell PhD Expert
Answered Aug 30, 2026
The x values are the second return argument of findpeaks(). It's the index number. Your formula does not have an x by name so you have to go with the index number. If you have a second  array for t, then to get the t values you'd do
 
 
[peakValues, indexes] = findpeaks(y);
tValues = t(indexes);
To get valleys, you invert the signal, so that now what used to be valleys are now peaks, and use findpeaks() again
 
 
invertedY = max(y) - y;
[peakValues, indexes] = findpeaks(invertedY);
tValues = t(indexes);
100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!