minor editing of current code of displaying 3 timestamps to displaying multiple timestamps with for and pause command

2 visualizzazioni (ultimi 30 giorni)
I did this code that displays the first 3 timestamps for temperature difference, but now i need to use for loop and pause command to change it to show multiple timestamps and how it changes each step with the pause command. I have edited it but its still wrong.
%%first 3 timestamps
n=5;
dt=1000;
k=15;
rho=8055;
Cp=480;
deltax=1.6;
x=linspace(-0.8,0.8,n);
deltax = x(2)-x(1);
T=zeros(1,5); T(1,1)=40; T(1,5)=40;
figure
plot(x,T)
title('Temperature distribution for first 3 timestamps')
xlabel('x')
ylabel('Temperature')
hold on;
T_old = T;
T(2:end-1) = T_old(2:end-1) + k/(rho*Cp) * dt * (T_old(3:end)-2*T_old(2:end-1)+T_old(1:end-2))/(deltax.^2);
plot(x,T)
hold on
T_old = T;
T(2:end-1) = T_old(2:end-1) + k/(rho*Cp) * dt * (T_old(3:end)-2*T_old(2:end-1)+T_old(1:end-2))/(deltax.^2);
plot(x,T)
%%multiple timestamps
n=5;
dt=1000;
k=15;
rho=8055;
Cp=480;
deltax=1.6;
x=linspace(-0.8,0.8,n);
deltax = x(2)-x(1);
T=zeros(1,5); T(1,1)=40; T(1,5)=40;
t = 0;
dt = 1000;
for c = 1:t
for r = 1:t
T(r,c) = 1/(r+c-1);
pause(1000);
end
end
figure
plot(x,T)
title('Temperature distribution for first multiple timestamps')
xlabel('x')
ylabel('Temperature')

Risposte (1)

Ramtej
Ramtej il 14 Set 2023
Hi,
I assume that you are trying to plot Temperature distribution at every time step with dt=1000.
Since, I donot know your implementation details, I'm suggesting a possible workaround on how to plot your data at each time step.
%% define a figure and assign title, xlabel and ylabel to it
fig = figure;
title('Temperature distribution for first multiple timestamps')
xlabel('x')
ylabel('Temperature');
hold on % make sure use turn on the hold to plot the subsequent plots into the same figure
for t = 0:1000:350000
% calculate or update the temperature distrubution at the time t
T = yourFunction(t);
plot(fig,x,T);
pause(1); % pause the plotting for a second to observer the distribution at the time t
end
hold off
Hope this resolves your query!

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by