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
댓글 수: 0
채택된 답변
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 Center 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!