"Index exceeds the number of array elements (11)."
1 view (last 30 days)
Show older comments
James Perkins
on 14 Oct 2019
Commented: James Perkins
on 14 Oct 2019
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
0 Comments
Accepted Answer
Guillaume
on 14 Oct 2019
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.
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements 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!