Need help storing and using values from an array
3 views (last 30 days)
Show older comments
barry conrad
on 10 Dec 2018
Edited: Image Analyst
on 10 Dec 2018
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 Comments
Accepted Answer
Image Analyst
on 10 Dec 2018
Edited: Image Analyst
on 10 Dec 2018
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 Comments
More Answers (0)
See Also
Categories
Find more on Function Creation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!