How to fix: Index exceeds the number of array elements (4).

조회 수: 1 (최근 30일)
SITI HASANAH
SITI HASANAH 2020년 6월 24일
답변: Urmila Rajpurohith 2020년 6월 30일
Hello, im write a coding to estimate the specific volume v of steam for the pressure range 0.01 through 10MPa and temperature range 400 degree Celcius through 1000 degree Celius using the ideal gas equation
but i got the error where it said "Index exceed the number of array elements(4) so I confuse about this error
fid = fopen('abc.txt','w');
Vact= [31.06300,40.29600,49.52700,58.75800;
6.209400,8.057700,9.904700,11.75130;
0.306610,0.401110,0.494380,0.587210;
0.073430,0.098860,0.122920,0.146530;
0.039958,0.055665,0.069856,0.083571;
0.026436,0.038378,0.048629,0.058391];
P = [0.01,0.05,1,4,7,10];
T = [673.15,873.15,1073.15,1273.15];
for i=1:6
for j=1:4
vol(i,j) = ((0.000461631).*T(j))./P(i);
end
end
% Calculate %error
for i=1:6
for j=1:4
error(i,j) = 100.0*(vol(i,j)-Vact(i,j))/Vact(i,j);
end
end
  댓글 수: 5
Stephen23
Stephen23 2020년 6월 25일
You definitely should NOT name any variable error, as this shadows the very important inbuilt error function.
SITI HASANAH
SITI HASANAH 2020년 6월 25일
so it i should change variable error with other variable?

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

답변 (1개)

Urmila Rajpurohith
Urmila Rajpurohith 2020년 6월 30일
yes,you can replace the variable error with any other variable name;
The best suggestion is not to use inbuilt function names as variable names.
To check if any variable share a name with a built-in function you can use the which function.
For example :
>> error = 2;
>> which -all error
error is a variable.
C:\Program Files\MATLAB\R2020b\toolbox\matlab\connector2\logger\+connector\+internal\Logger.p % Shadowed connector.internal.Logger method
C:\Program Files\MATLAB\R2020b\toolbox\simulink\dependency\analysis\@dependencies\error.p % Shadowed dependencies method
built-in (C:\Program Files\MATLAB\R2020b\toolbox\matlab\lang\error)
% Shadowed
Hope this helps!

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by