How to plot T versus t (time)?
显示 更早的评论
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
回答(1 个)
Star Strider
2020-8-16
Try this (after the loop):
figure
plot(t,T)
grid
xlabel('t')
ylabel('T')
xlim([0 1400])
.
3 个评论
Alex
2020-8-16
Star Strider
2020-8-16
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
2020-8-16
For completeness, it creates this plot:

类别
在 帮助中心 和 File Exchange 中查找有关 Title 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!