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

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

Guillaume
Guillaume il 14 Ott 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.

Più risposte (0)

Categorie

Scopri di più su Dictionaries in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by