Need help storing and using values from an array
3 次查看(过去 30 天)
显示 更早的评论
I'm trying to learn how to store values in an array. I was trying to create a list of 200 values for Tin which is the temperature using the last value of Tin for the next as well. t is the time ranging from 1:200. I coudn't find any relevant sources online :( Thanks for any help. If there are any questions I would happily explain the parts of my code. (Sorry for reupload -- I wasn't getting any useful help). I haven't used arrays before and the ones on the internet weren't any help, so go easy on me.
clear
t=zeros(200,1); %unsure
h= 1.6;
w=1.2;
l=1.8;
a=40;
Tin = 5;
Tout=5;
Theater=40;
M=0.25;
dt=1;
heaterState = 1;
Tlower = 21;
Tupper = 24;
dT=0;
c=1005.4;
for t1=1:200 % t is the time and
Tin = Tin+dT;
if Tin>Tupper
heaterState =0;
elseif Tin< Tlower
heaterState =1;
end
[Qloss,m] = getQloss(Tin,Tout,dt,h,w,l,a);
if heaterState ==1
[Qheat] = getQheater(Tin,Theater,M,dt);
else
Qheat = 0;
end
dT = (Qheat - Qloss)*(1/(m*c));
t(t1)=norm( %unsure
end
0 个评论
采纳的回答
Image Analyst
2018-12-10
编辑:Image Analyst
2018-12-10
You need to index Tin in your loop:
Tin(t1) = ....whatever......t1 must be an integer.
something = .... Tin(t1) ... use Tin(t1) instead of Tin.
If Tin is supposed to be 5 the first time through, do this:
if t1 == 1
Tin(t1) = 5;
else
Tin(t1) = Tin(t1-1) + dt;
end
Then everywhere else in your loop that you use Tin, you need to use Tin(t1) instead.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!