MATLAB Answers


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

Asked by James Perkins on 14 Oct 2019
Latest activity Commented on by 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')
disp('Under Damped')


Sign in to comment.

1 Answer

Answer by Guillaume
on 14 Oct 2019
 Accepted Answer

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:
index into this disp variable instead of calling the disp function. This variable has indeed only 11 elements, whereas
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.

  1 Comment

Thank you, got it working now!
That is a good lesson!

Sign in to comment.