getting error in for loop

3 次查看(过去 30 天)
Nudrat Sufiyan
Nudrat Sufiyan 2022-5-30
评论: Torsten 2022-5-30
Array indices must be positive integers or logical values.
Error in Untitled4 (line 27)
Idsat(i)=r1*(Vgs-(r2)+Vds(i));
for i=0:length(Vds)
Idsat(i)=r1*(Vgs-(r2)+Vds(i));
end
  1 个评论
Sam Chak
Sam Chak 2022-5-30
Have you checked if your array indices are positive integers or logical values?

请先登录,再进行评论。

回答(2 个)

Torsten
Torsten 2022-5-30
编辑:Torsten 2022-5-30
Loop indices don't start at 0, but at 1 in MATLAB:
for i=1:length(Vds)
Idsat(i)=r1*(Vgs-(r2)+Vds(i));
end
instead of
for i=0:length(Vds)
Idsat(i)=r1*(Vgs-(r2)+Vds(i));
end

Nudrat Sufiyan
Nudrat Sufiyan 2022-5-30
Thanks , but it still showing error.
can you please check my code once
clc;
m=0.23; %#1%
q=1.6e-19;
Nd=5e18;
d1=22e-7;
d2=1e-7;
a0=3.189e-8;
a1=(-0.077*m+3.189)*1e-8;
c13=(5*m+103);
c33=(-32*m+405);
e33=(0.72*m+0.73)*1e-4;
e31=(-0.11*m-0.49)*1e-4;
fis=1.4*m+0.87;
deff=23.01e-7;
detaEg=6.13*m+(1-m)*3.42-m*(1-m)+(m-1)*3.42;
detaEc=0.7*detaEg;
EA=(8.9-0.4*m)*8.85e-14;
Eoff=EA+((e33)^2)/c33;
EF=2.1;
sigema=((-m*(5.2e-6))+(2*(a0-a1)/a1)*(e31-e33*c13/c33)*1e-4);
Ppz=(2*(a0-a1)/a1)*(e31-e33*c13/c33)*1e-4;
r1=q*EA/deff;
r2=fis-(EF-(detaEc+q^2/EA*sigema^2*d2))/q;
Vgs=-2;
Vds=0:0.01:0.8;
for i=1:length(Vds)
Idsat(i)=r1*(Vgs-(r2)+Vds(i));
end
xlabel('vds');
ylabel('Idsat');
plot(Vds,Idsat)
  7 个评论
Torsten
Torsten 2022-5-30
编辑:Torsten 2022-5-30
It varies, but you don't see it in the plot since r2 = -7.731499999999999e+18.
Do you understand what I mean ?
If you plot a variable
T = 100000000 + 0:0.01:0.8
you won't see the 0:0.01:0.8.
Torsten
Torsten 2022-5-30
@Nudrat Sufiyan comment moved here
It means I should change the value of r2

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by