MATLAB: Rotate 3D-Figure during simulation

3drotatesimulation

Hi! I made a very easy simulation of the behaviour of a circular plane wave using the editor. Here's my code
figure
A = 4; % Amplitude
T = 1; % Period
w = 2*pi/T;
l = 3; % Wavelenght
k = 2*pi/l;
[x , y] = meshgrid(-10:0.1:10);
r = sqrt((x).^2+(y).^2);
for t = 0:0.01:10
z = A.*sin(k*r - w*t);
mesh(z)
xlim([0 200]);
ylim([0 200]);
zlim([-10 10]);
pause(0.01)
end
The code works properly and i see the wave propagates. I can't rotate the 3D-view with the button on the Figure, because when Matlab plot the new configuration of the wave, it restores the original view of the axis. Is there a way to do that?
Thanks in advance for your support!

Best Answer

Set up the xlim and so on once before the loop, and call hold on before the loop.
The first time you call mesh, store the output in a variable
H = mesh(z);
After that, do not call mesh again: instead
set(H, 'zdata', z)
When you have new data to plot.
Remember to call drawnow() after the mesh() and set() calls
Related Question