Q:

How to find slope changes?

I have calculated average horizontal values, their local minima points and plotted them. Now i have to find the valleys like first valley is negative to positive and 2nd valley is positive to negative. For this I have read somewhere that these valleys can be found by finding the slope change? can anyone help me out how to find the slope changes at specified points.

A:

We can do it this way:
dx = diff(x);
dx = [0 dx];          %shifting because diff has one less element
dx1 = [dx(2:end) 0];  %shifting dx for 1 element

r1 = find( dx>0 & dx1<0);  %compare dx and dx1 to find peaks
r2 = find( dx<0 & dx1>0);  %compare dx and dx1 to find valleys

So if you need only first peak you have take r1(1), only second valley - r2(2) etc
Hope it helps!

