Sraightforward, "brain-dead" solution would seem to be
indp=false(1,length(x)-5+1);
for ix=3:length(x)-2
indp(ix-2)=max(x(ix-2:ix+2)==x(ix));
end
Make the obvious fixup for the indm (minimum). Returns a logical vector of locations that meet the positive criterion. An alternate return of location and/or value is an (also hopefully obvious) extension.
accumarray could be useful in vectorizing, undoubtedly.
ADDENDUM:
>> x=round(10*rand(1,10))
x =
6 4 8 5 4 9 8 6 6 6
>> accumarray([1:6]',[3:8]',[],@(ix) max(x(ix-2:ix+2))==x(ix))'
ans =
1 0 0 1 0 0
>>
NB1: I adjusted spacing above to lineup the values w/ those of the input for visual comparison
On retrospect, you'll probably want to pre-/post-pend the two False values to have the return vector the same length as the original in this implementation or use the actual locations instead.
That is,
>> [x;false(1,2) accumarray([1:6]',[3:8]',[],@(ix) max(x(ix-2:ix+2))==x(ix))' false(1,2)]
ans =
6 4 8 5 4 9 8 6 6 6
0 0 1 0 0 1 0 0 0 0
>>
NB2: Substitute appropriate length values in place of the constant subscripting vectors above.