I had an attempt at vectorising and came up with this, however, it just ouputs a grey image:
i1 = double(imread("IMG_5704.JPG"));
dim = size(i1);
iOutput = zeros(size(i1));
w = 5; % specifies the size of the box (w = 3 means a 3x3 box)
r = fix(w/2); % 'radius' of box, excluding centre pixel
i = (r+1):dim(1)-(r+1);
j = (r+1):dim(2)-(r+1);
kernel = i1([i-r:i+r],[j-r:j+r],:);
iBlur(i,j,:) = mean(kernel,'all');