필터 지우기
필터 지우기

Need help storing and using values from an array

조회 수: 1 (최근 30일)
barry conrad
barry conrad 2018년 12월 10일
편집: Image Analyst 2018년 12월 10일
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

채택된 답변

Image Analyst
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개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by