from Fast array peak finder by George Zipfel
Finds locations of all maxima and corresponding maximum values in a 1D array.

peak=zipeaks(y)
function peak=zipeaks(y)
%Usage:  peak=zipeaks(y);
%Returns 2x(number of maxima) array
%peak(1,:) = value at maximum
%peakloc(2,:) = index value for maximum

%Find locations of local maxima
%yD=1 at maxima, yD=0 otherwise, end point maxima excluded
    N=length(y)-2;
    yD=[0 (sign(sign(y(2:N+1)-y(3:N+2))-sign(y(1:N)-y(2:N+1))-.1)+1) 0];
%Indices of maxima and corresponding values of y
    Y=logical(yD);
    I=1:length(Y);
    peak(1,:)=I(Y);
    peak(2,:)=y(Y);
    

Contact us at files@mathworks.com