"Index in position 3 exceeds array bounds (must not exceed 1)." for surf function of 2D transient heat transfer

조회 수: 1 (최근 30일)
Hi, I'm having a problem with some code based on the time loop for a 2D finite difference transient heat transfer problem. It comes up with the error "Index in position 3 exceeds array bounds (must not exceed 1)." for line 140 (the surf function). Here is the code for the time loop, I know the error must be something I have missed with the start or end of the time loop. Any help would be much appreciated.
for t=1:((t_f/dt))
for i=1:nx % Cold bottom part
T(i,ny,t)=T2;
end
for it=1:100
for i=2:(nx-1)
for j = 2:(ny-1)
if j==1 %PV panel plate
T(i,j,t+1)= (r1*(T(i+1,j,t)-2*T(i,j,t)+T(i-1,j,t)+(-2*T(i,j,t)+2*T(i,j-1,t)+(q*dx)/k2))+T(i,j,t));% plate temperatures
elseif j>=2
if i==1 %Insulated LHS temp
T(i,j,t+1)= r1*(2*T(i+1,j,t)-2*T(i,j,t)+(-2*T(i,j,t)+T(i,j-1,t)+T(i,j+1,t)))+T(i,j,t);
elseif i==nx %Insulated RHS temp
T(i,j,t+1)= r1*(2*T(i-1,j,t)-2*T(i,j,t)+(-2*T(i,j,t)+T(i,j-1,t)+T(i,j+1,t)))+T(i,j,t);
end
end
for j=2:Finlength; %Fin temperatures
if i ==minVal %Fin1
T(i,j,t+1)=alphaaluminium*dt*((T(i+1,j,t)-2*T(i,j,t)+T(i-1,j,t))/(dx^2)+(T(i,j+1,t)-2*T(i,j,t)+T(i,j-1,t))/(dy^2))+T(i,j,t);
elseif i == minVal+minVal %Fin2
T(i,j,t+1)=alphaaluminium*dt*((T(i+1,j,t)-2*T(i,j,t)+T(i-1,j,t))/(dx^2)+(T(i,j+1,t)-2*T(i,j,t)+T(i,j-1,t))/(dy^2))+T(i,j,t);
end
end
if j~=2:Finlength; %
if i~=minVal;
T(i,j,t+1)=alphawax*dt*((T(i+1,j,t)-2*T(i,j,t)+T(i-1,j,t))/(dx^2)+(T(i,j+1,t)-2*T(i,j,t)+T(i,j-1,t))/(dy^2))+T(i,j,t);
end
end
end
end
end
x=linspace(0,platelength,nx);
y=linspace(0,plateheight,ny);
% [x_arr,y_arr] = meshgrid(x,y);
surf(y,x,T(:,:,t+1))
end

답변 (0개)

카테고리

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

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by