Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Nur Zawani Rosli
Nur Zawani Rosli le 29 Juin 2021
Commenté : Nur Zawani Rosli le 29 Juin 2021
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

Réponse acceptée

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

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by