How do I print and save the graphs at each n?

1 次查看(过去 30 天)
I tried using eval(['print -djpeg part2_' num2str(t) '.jpeg']); , however, it replaces the old one with new graph each time. At the end, it only shows the latest and newest graph.
clear all
clc
%Inputs
alphaA = 1e-6;
alphaB = 2e-6;
delta_t = 15;
xlength = 20*10^-3;
nx = 20;
delta_x = xlength/nx;
% Arrays
x=[linspace(0,20,21);
linspace(0,20,21);
linspace(0,20,21);
linspace(0,20,21);
linspace(0,20,21);
linspace(0,20,21)];
y=[zeros(1,21);
ones(1,21);
2*ones(1,21);
3*ones(1,21);
4*ones(1,21);
5*ones(1,21)];
%Initial Condition
T=300*ones(6,21,1);
%Boundary Conditions
T(1,:,1) = 320;
T(6,:,1) = 310;
T(:,1,1) = 300;
T(:,21,1) = 300;
dA = alphaA*0.05/delta_x^2;
dB = alphaB*0.05/delta_x^2;
dT = delta_t*20;
d = dA*ones(6,21);
d(1:3,1:4)=dB;
d(1:4,19:21)=dB;
for n=1:dT
T(1,:,n) = 320;
T(6,:,n) = 310;
T(:,1,n) = 300;
T(:,21,n) = 300;
for j=2:5
for i=2:20
T(j,i,n+1) = T(j,i,n) + d(j,i)*(T(j+1,i,n)+T(j-1,i,n)-4*T(j,i,n)+T(j,i+1,n)+T(j,i-1,n));
end
end
contourf(x,y,T(:,:,n))
pause(0.01);
end

采纳的回答

Walter Roberson
Walter Roberson 2021-6-29
filename = sprintf('part2_%d.jpeg', n);
print('-djpeg', filename);
after the pause()

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by