Filter löschen
Filter löschen

Need help storing and using values from an array

1 Ansicht (letzte 30 Tage)
barry conrad
barry conrad am 10 Dez. 2018
Bearbeitet: Image Analyst am 10 Dez. 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

Akzeptierte Antwort

Image Analyst
Image Analyst am 10 Dez. 2018
Bearbeitet: Image Analyst am 10 Dez. 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.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by