you can use movmax(A,k) function which returns an array of local k-point maximum values for Array A, where each maximum is calculated over a sliding window of length k across neighboring elements of A. When k is odd, the window is centered about the element in the current position. When k is even, the window is centered about the current and previous elements. The window size is automatically truncated at the endpoints when there are not enough elements to fill the window. When the window is truncated, the maximum is taken over only the elements that fill the window.
for more information on movmax you can follow the below link