% Draw a 3D-surface
function anim_camera(fname)

% draw a sombrero and turn it around
n = 50;
x = y = linspace (-8, 8, n)';
[xx, yy] = meshgrid (x, y);
r = sqrt (xx .^ 2 + yy .^ 2) + eps;
c = 5 * sin (r) ./ r;

h= surf(xx,yy,c,c);
shading interp

m = moviefile(fname);

for angle=linspace(0,2*pi,50)
  set(gca,'CameraPosition',20*[sin(angle) 0 cos(angle) ]);
  set(gca,'CameraUpVector',[-cos(angle) 0 sin(angle) ]);
  
  drawnow
  sleep(.01)
  m = movieaddframe(m);
end

m = movieclose(m);