How do I make just one plot stay in a figure, while other plots are removed/updated as I iterate through my loop

4 次查看(过去 30 天)
I'm trying to make the plot of a potential visible in my figure while I plot the time evolution of the wave function of a particle in the potential.
V=diag(xvec.^2); %V is potential and xvec is a vector
figure(1)
hold on
plot(xvec,V);
And after this point I want "hold on" command to be turned off for the animation to make sense, but the plot of the potential V to still appear in my figure, while the loop below iterates through the time evolution.
for t=0:dt:100*dt
v=exp(-i*E(1:N)*t/hbar);
Psi=v'*ev(:,1:N)'/sqrt(N);
plot(xvec,abs(Psi).^2/dx)
axis([-0.1*a 1.1*a 0 4])
text(2.5*a,0.45,num2str(t))
pause(.2)
end

采纳的回答

Walter Roberson
Walter Roberson 2017-3-2
V=diag(xvec.^2); %V is potential and xvec is a vector
fig = figure(1);
ax = axes('Parent', fig);
hold(ax, 'on')
plot(ax, xvec, V);
for t=0:dt:100*dt
v = exp(-i*E(1:N)*t/hbar);
Psi = v'*ev(:,1:N)'/sqrt(N);
y = abs(Psi).^2/dx;
if t == 0
ph = plot(ax, xvec, y)
axis(ax, [-0.1*a 1.1*a 0 4])
th = text(ax, 2.5*a, 0.45, num2str(t));
else
set(ph, 'YData', y);
set(th, 'String, num2str(t));
end
pause(.2)
end
hold(ax, 'off')

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by