How to solve index bounds problem

1 visualización (últimos 30 días)
Das Bably
Das Bably el 12 de Mzo. de 2013
Hi
I am just a beginner in MATLAB,Now I am trying to do a code but getting error. i am copying the code,
function [p1]=element1()
L=input('Length of pipe =');
C=input('speed of sound=');
d=input('Pipe diameter=');
M=input('Mach number=');
S=pi*(d/2)^2;
frequency=0:6:6486;
K=2*pi*frequency/C;
Kc=K/(1-M^2);
Y=C/S;
KcL=Kc*L;
KcML=Kc*(L*M);
p1=zeros(2,2164);
n=1;
for i=0:1:1082
p1(:,(2*n-1):(2*n))=exp(-i*KcML(n)).*[cos(KcL(n)),i*Y*sin(KcL(n));i*sin(KcL(n))/Y,cos(KcL(n))];
n=n+1;
end
The error message is
??? Attempted to access KcML(1083); index out of bounds because
numel(KcML)=1082.
Error in ==> element1 at 27
p1(:,(2*n-1):(2*n))=exp(-i*KcML(n)).*[cos(KcL(n)),i*Y*sin(KcL(n));i*s
Thanks Advancely

Respuesta aceptada

Walter Roberson
Walter Roberson el 12 de Mzo. de 2013
n is 1 when i is 0. n is 2 when i is 1. n is 3 when i is 2. So when i is 1082 what is n going to be?
  2 comentarios
Das Bably
Das Bably el 12 de Mzo. de 2013
Thanks what kind of change in my code should I do could you please suggest me?
Das Bably
Das Bably el 12 de Mzo. de 2013
Editada: Das Bably el 12 de Mzo. de 2013
If I use n=i+1 then i am getting ans of 2x2164 is it ok? I am confused,

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Just for fun en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by