index exceed matrix dimensions

2 visualizaciones (últimos 30 días)
Oday Shahadh
Oday Shahadh el 10 de Feb. de 2021
Comentada: KALYAN ACHARJYA el 10 de Feb. de 2021
Hi, every body
why I have an index exceed matrix dimesnions in this code, pls help
z1=linspace(0,D,1000);
z2=linspace(0,D1,1000);
z3=linspace(0,D2,1000);
z=[z1,z2,z3];
Dv=[D,D1,D2];
for j =1:3
p1i=(4*mu*N*I)/(pi*L);
p2i=1./((((z(j)./(L./2)).^2)+1).*sqrt(((z(j)./(L./2)).^2)+2));
p3i=1./(((((z(j)-D(j))./(L./2)).^2)+1).*sqrt((((z(j)-D(j))./(L./2)).^2)+2));
Bi=(p1i*(p2i+p3i))*10000;
end

Respuesta aceptada

KALYAN ACHARJYA
KALYAN ACHARJYA el 10 de Feb. de 2021
Editada: KALYAN ACHARJYA el 10 de Feb. de 2021
Issue with this line
p3i=1./(((((z(j)-D(j))./(L./2)).^2)+1).*sqrt((((z(j)-D(j))./(L./2)).^2)+2));
You are trying to access D as a vector, is that so?
Also you used D in the following line also
z1=linspace(0,D,1000);
D might be scalar data (one numeric value), as per z1 statement
More: It may be typo mistake, D may be Dv, bacause you have defined Dv, but not use anywhere in the code.
  2 comentarios
Oday Shahadh
Oday Shahadh el 10 de Feb. de 2021
Oh my God , I did not noticed this, but why I got just three values while it must be result a set of data as the same length of z
z1=linspace(0,D,1000);
z2=linspace(0,D1,1000);
z3=linspace(0,D2,1000);
z=[z1,z2,z3];
Dv=[D,D1,D2];
Bii=[];
for j =1:3
p1i=(4*mu*N*I)/(pi*L);
p2i=1./((((z(j)./(L./2)).^2)+1).*sqrt(((z(j)./(L./2)).^2)+2));
p3i=1./(((((z(j)-Dv(j))./(L./2)).^2)+1).*sqrt((((z(j)-Dv(j))./(L./2)).^2)+2));
Bi=(p1i*(p2i+p3i))*10000;
Bii=[Bi Bii];
end
KALYAN ACHARJYA
KALYAN ACHARJYA el 10 de Feb. de 2021
See the for loop j, 1 to 3 only. Note Dv having length 3 only

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by