index exceed matrix dimensions

2 次查看(过去 30 天)
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

采纳的回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2021-2-10
编辑:KALYAN ACHARJYA 2021-2-10
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 个评论
Oday Shahadh
Oday Shahadh 2021-2-10
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 2021-2-10
See the for loop j, 1 to 3 only. Note Dv having length 3 only

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by