Making a 2D pyramid in MATLAB

Make a square-base 2D data pyramid in Matlab, where:

N
number of pixels per side (e.g. 512)
MinVal
minimum data value (e.g. 0)
MaxVal
maximum data value (e.g. 65535)
N = 256;
MinVal = 0;
MaxVal = 2^16 - 1;

data = nan(N);
temp = uint16(MinVal:round((MaxVal-MinVal)/(N/2)):MaxVal);

for i = 1:N/2
  data(i,i:end-i+1) = temp(i);
  data(i:end-i+1,i) = temp(i);
  data(end-i+1,i:end-i+1) = temp(i);
  data(i:end-i+1,end-i+1) = temp(i);
end

figure, mesh(data)

The values at the “base” of the pyramid are zero, and increase linearly on each side to 65,535. This sort of figure might be useful when testing an optical flow algorithm.