perhaps the best way, but this is similar to your example.
mapArray = [9, 8, 7, 800
8, 7, 6, 800
21, 1, 3, 800
800, 800, 800, 800];
% find row, col indices of the search value
[r,c]=find(mapArray==800)
% compute indexes, plus and minus one
r2=[r-1;r+1;r+1;r-1;r-1 ; r+1 ; r; r];
c2=[c+1;c-1;c+1;c-1; c ; c ; c+1 ;c-1];
% new variable
mapArrayNew = mapArray;
% only use valid indices.
ixKeep = r2<=size(mapArray,1) & c2<=size(mapArray,2) & r2>0 & c2>0;
% replace
mapArrayNew(sub2ind(size(mapArray),r2(ixKeep),c2(ixKeep))) = 700;