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 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