Effacer les filtres
Effacer les filtres

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

4 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Walter Roberson
Walter Roberson le 2 Mar 2017
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')

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Performance dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by