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

조회 수: 1 (최근 30일)
Nur Zawani Rosli
Nur Zawani Rosli 2021년 6월 29일
댓글: Nur Zawani Rosli 2021년 6월 29일
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에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by