index exceed matrix dimensions

2 ビュー (過去 30 日間)
Oday Shahadh
Oday Shahadh 2021 年 2 月 10 日
コメント済み: KALYAN ACHARJYA 2021 年 2 月 10 日
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 Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by