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

1 visualización (últimos 30 días)
Nur Zawani Rosli
Nur Zawani Rosli el 29 de Jun. de 2021
Comentada: Nur Zawani Rosli el 29 de Jun. de 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

Respuesta aceptada

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

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by