"Index in position 3 exceeds array bounds (must not exceed 1)." for surf function of 2D transient heat transfer
    3 views (last 30 days)
  
       Show older comments
    
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 Comments
Answers (0)
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!