Effacer les filtres
Effacer les filtres

My 'For' sequence is giving me "Array indices must be positive integers or logical values."

1 vue (au cours des 30 derniers jours)
This is my code, can you tell me whats wrong with it, please?
a = 1;
pi = 3.14159265359;
b = (540/2)/1000; %mm
rho = 8960; %kg/m3
c = 385; % J/(K·kg)
k = 400; % W/(K·m)
alpha = k/(rho*c);
y = input('y = ');
t = input('t=');
for i= 0:100
x =((-1)^a(i))/((a(i)+(1/2))*pi)*e^(-(a(i)+(1/2))^2*pi^2*alpha*t/b^2)*cos(a(i)+(1/2))*pi*y/b
x1 = 2*x
end
  2 commentaires
per isakson
per isakson le 7 Mai 2018
Modifié(e) : per isakson le 7 Mai 2018
Replace
for i= 0:100
by
for ii = 0:100
i = ii - 1;
And pi is already defined in Matlab
Arantxa Abascal
Arantxa Abascal le 7 Mai 2018
Thanks, but it's still not working, i think there's something else wrong.

Connectez-vous pour commenter.

Réponse acceptée

Siyu Guo
Siyu Guo le 7 Mai 2018
Array index in MATLAB starts from 1 instead of 0.
  2 commentaires
Arantxa Abascal
Arantxa Abascal le 7 Mai 2018
Thanks! I changed it but know it says " Index exceeds array bounds."
Arantxa Abascal
Arantxa Abascal le 7 Mai 2018
Nevermind, that was it! thank you very much!!!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by