find local max in time window

J
Jessica · Jan 27, 2021 · 2K views
Question
I'm  trying to find the local max in time window , i know that I have to define part from the signal then use the findpeaks built in function then take the max value of it.   % code pks_value=[];this to store the max value from the peaks step=200; pcg=pcg_lp2'; for i=1:200:N temp=pcg(i:i+step); [pks,locs] = findpeaks(temp); pks_value(i)=max(pks); end it give me the error msg "Index exceeds matrix dimensions. " so how to fix it , what to change
Expert Answer
Profile picture of John Williams
John Williams PhD Expert
Answered Aug 11, 2026

If you have a recent copy of MATLAB, try using movmax().

This should get you started:
 
x = randi(10,150,1);
tmp = movmax(x,5);
imvmax = find(x==tmp);
mvmax = x(imvmax);
plot(1:length(x),x,'-',imvmax,mvmax,'o')
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!