"Index exceeds the number of array elements (11)."

1 次查看(过去 30 天)
Hi, Im pretty new to MATLAB and have come across this issue. Every time i run the script i get a message saying "Index exceeds the number of array elements (11).". Please could someone help?
disp = ('RLC Circuit')
R = input('R = ');
L = input('L = ');
C = input('C = ');
a = L*C;
b = R*C;
c = 1;
D = (b^2)-(4*a*c)
S1 = -b+(sqrt(D))/(2*a)
S2 = -b-(sqrt(D))/(2*a)
if D>0
disp('Over Damped')
elseif D==0
disp('Critically Damped')
else
disp('Under Damped')
end

采纳的回答

Guillaume
Guillaume 2019-10-14
You create a variable called disp:
disp = 'RLC Circuit' %removed brackets which didn't anything
Which shadows the built-in disp function. From then on:
disp('something')
index into this disp variable instead of calling the disp function. This variable has indeed only 11 elements, whereas
disp('Over')
tries to access elements 79, 118, 101, 114 (the character values of 'Over').
Morale of the story: don't use the names of matlab function as variable names. Other common culprits are sum, mean, max, and min.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by