getting error in for loop

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 commentaire

Sam Chak
Sam Chak le 30 Mai 2022
Have you checked if your array indices are positive integers or logical values?

Connectez-vous pour commenter.

Réponses (2)

Torsten
Torsten le 30 Mai 2022
Modifié(e) : Torsten le 30 Mai 2022

0 votes

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 le 30 Mai 2022

0 votes

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 commentaires

Nudrat Sufiyan
Nudrat Sufiyan le 30 Mai 2022
As, I want to plot Idsat and Vds curve.
Torsten
Torsten le 30 Mai 2022
The code works fine for me.
Nudrat Sufiyan
Nudrat Sufiyan le 30 Mai 2022
for me it's showing an horizontal line. Can you please send the output
r1 = 5.420307692307692e-26
Vgs = -2
r2 = -7.731499999999999e+18
Thus Vds won't change anything if you have in mind how large r2 is.
Nudrat Sufiyan
Nudrat Sufiyan le 30 Mai 2022
As vds must varies with Ids. For this what I need to change in the code.
Torsten
Torsten le 30 Mai 2022
Modifié(e) : Torsten le 30 Mai 2022
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 le 30 Mai 2022
@Nudrat Sufiyan comment moved here
It means I should change the value of r2

Connectez-vous pour commenter.

Commenté :

le 30 Mai 2022

Community Treasure Hunt

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

Start Hunting!

Translated by