Attempted to access Tg_in(2); index out of bounds because numel(Tg_in)=1.
2 views (last 30 days)
Show older comments
Hello, I am working on a project which needs matlab. I am new to matlab and have only basic information. Now I have found a paper which included a matlab code. I am trying to understand it. So when I type the code and run the simulation matlab gives me this error: "Attempted to access Tg_in(2); index out of bounds because numel(Tg_in)=1."
The for loop for this code is:
for m=1:NN %MM
rho_g(m)=354.6E0/Tg_in(m); %density(Tg_in) [kg/m^3]
Mass_input(m)=SV_in(m)/3600.0E0*Vo1ume*rho_g_STP; %Tota1 mass input [Kg/s]
mass_input_cell(m)=Mass_input(m)/num_cell; %Mass f1ow rate per cell [Kg/s]
q_input_cell(m)=mass_input_cell(m)/rho_g(m); %f1ow rate per cell [m^3/s]
u_in(m)=q_input_cell(m)/Ag; %f1ow ve1ocity [m/s]
Cair_in(m)=rho_g(m)/MOLEMASS_AIR*1.0E3;
Cnh3_in(m)=Cair_in(m)*Xnh3_in(m);
Cno_in(m)=Cair_in(m)*Xno_in(m);
Co2_in(m)=Cair_in(m)*0.08;
end
I have put NN=1000;
Can you guys help me to understand what is wrong in it?
2 Comments
Image Analyst
on 22 Mar 2015
You will understand it after you look at this. It's a magic link that solves virtually all problems like this. After that you will discover that Tg_in is not an array.
Accepted Answer
Geoff Hayes
on 22 Mar 2015
Adi - the error message is telling you that you the code is treating the Tg_in variable as if it were an array whereas you have defined it as a scalar. So within the second iteration of the for loop, there is an attempt to access
Tg_in(2)
and it fails because Tg_in is just a scalar. If you have defined NN to be 1000, then Tg_in must be an array (or vector) of 1000 elements. (The same is true for SV_in too.)
7 Comments
Geoff Hayes
on 24 Mar 2015
Adi - please ask a specific question rather than writing a number of them in the same post. It is unclear what the link to the complete code is that you mentioned. As for using an Excel file, use xlsread for read the data from file.
More Answers (0)
See Also
Categories
Find more on Logical 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!