Finding local max and min

Hey there,
first time poster but I have been working with matlab for nearly 2 years.

My problem is I have a given array called "stim".
When I plot as simply


it looks like this:

There is a brief period at the very beginning and the very end when stim hovers, with variety, around 0.

I need to find the points for all local max and min.

I tried using extrema, findpeaks with no success - I think there's too much fluctuations. If I zoom in to the peaks, you'll notice it:

I tried using a for and if loop such as

M=[]; % array of max values

for i=2:length(stim)
if stim(i) > stim(i-1) && stim(i) > (stim(i+1)
M = [M i];

With no success. I keep getting unwanted values. Can anyone help?
This has been torturing me for a while.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!