Attempted to access Tg_in(2); index out of bounds because numel(Tg_in)=1.

조회 수: 2 (최근 30일)
adi kul
adi kul 2015년 3월 22일
댓글: adi kul 2015년 3월 26일
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
Image Analyst
Image Analyst 2015년 3월 22일
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.
adi kul
adi kul 2015년 3월 22일
Hi Image analyst. Sorry but I don't understand these things. New to Matlab.

댓글을 달려면 로그인하십시오.

채택된 답변

Geoff Hayes
Geoff Hayes 2015년 3월 22일
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
Geoff Hayes
Geoff Hayes 2015년 3월 24일
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.
adi kul
adi kul 2015년 3월 26일
okay. anyhow I fixed the issues! Thank a lot for all your help and time :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by