MATLAB: How to have matlab extract the max value of a column within a moving range

excelImage Processing Toolboxmax valuemorphological dilation

So this is a little complicated, but I need matlab to extract the max value of a column within a range that changes based on surrounding values. So for example if I had a column that looked like this:
Row number Data value
1 0.5
2 0.2
3 1
4 0.5
5 0.1
6 0.8
7 2
8 0.3
9 0.7
10 0.8
11 0.4
12 0.3
13 0.7
14 1
What I'd like a program to do is extract the largest value within 5 rows of that value. So, for example, the code should extract the 2 in row seven because it is within 5 rows of the 1 in row 3. It should also extract the 1 in row 14 because it's more than 5 rows away from the 2 in row 7.
I'm very new to matlab and I've been playing around with the few functions I do know, but I'm getting pretty stuck because I need this code to be interactive with the data set. I'd really appreciate any help/suggestions you might have.
Thank you!

Best Answer

Use imdilate() if you have the Image Processing Toolbox. It's a moving max filter
kernel = [1;1;1;1;1]; % Vertical 5 by 1 filter.
result = imdilate(yourArray, kernel);
yourArray can be a 1 or 2 D array.