Fixed it.
[az, el] = deal(-30, 30) % initial view direction
for frame = 1:num_frames
surf(P(:, :, frame));
view([az, el]);
axis([1 16 1 16 0 max(max(max(P)))]);
pause(0.03)
[az, el] = view %update view direction
end
There were two problems. My syntax for setting the view azimuth and elevation was wrong. Also, I need to get the az and el after the pause. If I execute
[az, el] = view
before the pause it returns the old value most of the time.
I still need to understand the synchronization issues. Why do I need a pause to get the animation to run in the first place, and how long do I need to wait before the [az, el] = view command? Is there some sort of "wait for frame to be displayed" command?