How to plot T versus t (time)?
Mostrar comentarios más antiguos
Hello. I have a function of two variables and want to plot T as a function of t (time) or y. How can I do that? Thanks.
clc;
clear;
%----------------------------------------------------------------------
% INPUT
%----------------------------------------------------------------------
n=100; % number of iterations
Dp=30e-6;
h=Dp;
dy=h/n;
t_final=225*60;
t1=0.1*t_final;
dt=5;
To=298.15;
delta_T=274.15/60; % Temperature change [K/sec] (1 cel/min)
T_f=523.15;
%----------------------------------------------------------------------
% OUTPUT
%----------------------------------------------------------------------
t=0:dt:t_final;
y=0:dy:h;
Lt=length(t);
Ly=length(y);
% T
T=ones(Ly,Lt)*To;
% % Entering Loops
% % Defining Temperature
for j=1:Lt %time loop
for i=1:Ly %space loop
if t(j)<t1
T(i,j)=To-(y(i)/h)*delta_T*(1-t(j)/t1);
else
T(i,j)=To;
end
end
end
Respuestas (1)
Star Strider
el 16 de Ag. de 2020
Try this (after the loop):
figure
plot(t,T)
grid
xlabel('t')
ylabel('T')
xlim([0 1400])
.
3 comentarios
Alex
el 16 de Ag. de 2020
Star Strider
el 16 de Ag. de 2020
My pleasure!
I assume by ‘y’ you mean ‘T’. Since the columns of ‘T’ are calculated from ‘t’, choose whatever rows of ‘T’ (the first dimension) you want to plot. At least one dimension of ‘T’ (that appears to be the column or second dimension here) must be the same as the number of elements of ‘t’ or the plot will fail.
Image Analyst
el 16 de Ag. de 2020
For completeness, it creates this plot:

Categorías
Más información sobre Title en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!