Question
Here is my signal where i need to number the peaks and troughs in numbers as 1,2,3,4...
Expert Answer
Neeta Dsouza
PhD Expert
Answered Aug 14, 2026
Try findpeaks() in the Signal Processing Toolbox. Invert the signal to find valleys.
numPoints = 50; x = sort(rand(1, numPoints)); y = rand(1, numPoints); plot(x, y, 'k-', 'LineWidth', 2); grid on; [peakValues, indexesOfPeaks] = findpeaks(y); hold on; peakx = x(indexesOfPeaks); peaky = y(indexesOfPeaks); plot(peakx, peaky, 'r*', 'LineWidth', 2, 'MarkerSize', 10); % Find valleys on inverted signal [valleyValues, indexesOfValleys] = findpeaks(-y); valleyx = x(indexesOfValleys); valleyy = y(indexesOfValleys); hold on; plot(valleyx, valleyy, 'b*', 'LineWidth', 2, 'MarkerSize', 10);

Be careful with the first and last point of your data since it doesn't find those. You should look at the adjacent index (2 or end-1) if you want to classify them as either a peak or valley.
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
Related matlab Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →