index exceed matrix dimensions

3 vues (au cours des 30 derniers jours)
Oday Shahadh
Oday Shahadh le 10 Fév 2021
Commenté : KALYAN ACHARJYA le 10 Fév 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

Réponse acceptée

KALYAN ACHARJYA
KALYAN ACHARJYA le 10 Fév 2021
Modifié(e) : KALYAN ACHARJYA le 10 Fév 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 commentaires
Oday Shahadh
Oday Shahadh le 10 Fév 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 le 10 Fév 2021
See the for loop j, 1 to 3 only. Note Dv having length 3 only

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing 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