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

1 vue (au cours des 30 derniers jours)
James Perkins
James Perkins le 14 Oct 2019
Commenté : James Perkins le 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

Réponse acceptée

Guillaume
Guillaume le 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.
  1 commentaire
James Perkins
James Perkins le 14 Oct 2019
Thank you, got it working now!
That is a good lesson!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Dictionaries dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by