this code works fine when I run it. Looks pretty nice as well.
clear all; close all; clc;
psi0=1;
psi = zeros(100,100); % initializing variable for better memory management
lambda=1;
vphi=1;
k=2*pi/lambda;
omega=k*vphi; T=2*pi/omega;
[xx,yy]=meshgrid(linspace(-10,10,100),linspace(-10,10,100));
x=linspace(-3*lambda,3*lambda,100); % does not need to be within loop because not changing
y=x;
for t=0:0.005:2 %aici va fi ciclu in tema;
for ix=1:length(x)
for iy=1:length(y)
ro=sqrt(x(ix)^2+y(iy)^2);
if(ro>lambda/20)
psi(iy,ix)=psi0/ro*sin(omega*t-k*ro);
end
end
end
surf(xx,yy,psi);
zlim([-10 10]);
shading interp;
colormap spring;
drawnow;
end
but what are you trying to do? Do you want to save the movie to be played later outside of matlab? Than something like this might do the trick
clear all; close all; clc;
psi0=1;
psi = zeros(100,100); % initializing variable for better memory management
lambda=1;
vphi=1;
k=2*pi/lambda;
omega=k*vphi; T=2*pi/omega;
[xx,yy]=meshgrid(linspace(-10,10,100),linspace(-10,10,100));
x=linspace(-3*lambda,3*lambda,100); % does not need to be within loop because not changing
y=x;
idx = 1;
figure('DoubleBuffer','on','Renderer','painters');
for t=0:0.005:2 %aici va fi ciclu in tema;
for ix=1:length(x)
for iy=1:length(y)
ro=sqrt(x(ix)^2+y(iy)^2);
if(ro>lambda/20)
psi(iy,ix)=psi0/ro*sin(omega*t-k*ro);
end
end
end
surf(xx,yy,psi);
zlim([-10 10]);
shading interp;
colormap spring;
drawnow;
try
F(idx) = getframe(gcf);
catch
% if frame was closed before animation was finished than need to
% stop the code
return
end
idx = idx + 1;
end
movie(F)