Index in position 1 exceeds array bounds (must not exceed 2).
3 views (last 30 days)
Show older comments
ns = 1;
Ac = 1.68;
Cp = 4184;
emode = 1;
m_test = 0.023;
a0 = 0.745;
a1 = 2.3478;
a2 = 0.0005;
m_c = 0.03864;
Ti = 328;
To(1,1) = 328;
To(2,1) = 328;
Q_aux = 0;
t=1;
time(t,1)=60;
k_mL = 1;
it = 1380;
dt = 60;
fileID = fopen('x.txt','r');
indata = textscan(fileID, '%f %f %f', 'HeaderLines',1);
fclose(fileID);
storedvalue{1} = indata{1};
storedvalue{2} = indata{2};
storedvalue{3} = indata{3};
X_data = storedvalue{1};
Y1_data = storedvalue{2};
Y2_data = storedvalue{3};
if t == 1
Num_useful = 0;
Deno = 0;
end
for t=1:1:it
t = t+1;
time(t,1)= time(t-1,1) + dt/60;
minute = [60 120 180 240 300 360 420 480 540 600 660 720 780 840 900 960 1020 1080 1140 1200 1260 1320 1380 1440];
Ti1 = [327.71 327.42 327.11 326.75 326.29 325.54 323.92 321.44 319.11 317.11 315.34 314.14 313.16 312.05 311.3 310.15 308.8 307.76 304.07 299.47 297.1 295.47 295.02 294.5];
Ti (t,1) = interp1(minute,Ti1,time(t,1));
Ta1 = [290.2 290.2 290.2 290.8 290.2 289.7 290.8 290.2 290.8 291.3 291.3 291.9 291.9 291.9 291.9 291.9 291.3 290.8 290.8 290.2 290.8 290.2 290.2 290.2];
Ta(t,1) = interp1(minute,Ta1,time(t,1));
gt1 = [0 0 0 0 0 4.92 196.18 398.82 570.13 697.19 771.13 786.88 743.34 643.52 494.30 306.29 96.37 0 0 0 0 0 0 0];
gt(t,1) = interp1(minute,gt1,time(t,1));
xkatd = 0.0431;
storedvalue{4} = xkatd;
conv = 0.001;
xkat=0.85;
To1 = To(t-1,1);
for i = 1:500
frulp = a1 + a2*(Ti(t,1) - Ta(t,1));
fratio = 1;
FRTan = fratio*a0;
FRUl = fratio*a1;
FRtwo = fratio*a2;
FRUlp = fratio*frulp;
ratio = 1;
if Ti(t,1) < 323
Q_aux(t,1)=1500;
Ti(t,1)=Ti(t,1)+ Q_aux(t,1)/(m_c*Cp);
qu(t,1) = ratio*Ac*( FRTan*xkat*gt(t,1) - FRUlp*(Ti(t,1) - Ta(t,1)));
sf(t,1)=(qu(t,1)/(qu(t,1)+Q_aux(t,1)))*100;
To(t,1) = qu(t,1)/m_c/Cp + Ti(t,1);
elseif Ti(t,1) >= 333
Q_aux(t,1)=0;
Ti(t,1)=Ti(t,1);
qu(t,1) = ratio*Ac*( FRTan*xkat*gt(t,1) - FRUlp*(Ti(t,1) - Ta(t,1)));
sf(t,1)=(qu(t,1)/(qu(t,1)+Q_aux(t,1)))*100;
To(t,1) = qu(t,1)/m_c/Cp + Ti(t,1);
end
if (Ac <= 0) || (gt(t,1) <= 0) || (qu(t,1)<=0)
Effic(t,1) = 0;
qu(t,1)=0;
sf(t,1)=0;
else
Effic(t,1) = qu(t,1)/gt(t,1)/Ac;
end
end
if (abs(To(t,1) - To1) > conv)
To1 = To(t,1);
else
break;
end
if ( To(t,1) - Ti(t,1)) > 8
m_c = 0.03864;
elseif (To(t,1) - Ti(t,1)) < 0
m_c = 0;
end
end
end
I am getting the following error
Index in position 1 exceeds array bounds (must not exceed 2).
Error in Code (line 184)
if (abs(To(t,1) - To1) > conv)
Can someone please help me?
3 Comments
Answers (1)
Matt J
on 26 Jul 2020
How can To(t,1) make sense when t becomes greater than 2? To is only a length 2 vector.
3 Comments
Image Analyst
on 26 Jul 2020
Put in comments so we can understand what you did. Often when you do that you'll discover the error on your own. But at least then, if you still haven't found it, we'll have a chance at understanding what you did and what you want.
Matt J
on 26 Jul 2020
what can I do?
You should make sure To and other vector are the correct length.
See Also
Categories
Find more on Matrix Indexing 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!