Borrar filtros
Borrar filtros

getting error in for loop

3 visualizaciones (últimos 30 días)
Nudrat Sufiyan
Nudrat Sufiyan el 30 de Mayo de 2022
Comentada: Torsten el 30 de Mayo de 2022
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 comentario
Sam Chak
Sam Chak el 30 de Mayo de 2022
Have you checked if your array indices are positive integers or logical values?

Iniciar sesión para comentar.

Respuestas (2)

Torsten
Torsten el 30 de Mayo de 2022
Editada: Torsten el 30 de Mayo de 2022
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 el 30 de Mayo de 2022
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 comentarios
Torsten
Torsten el 30 de Mayo de 2022
Editada: Torsten el 30 de Mayo de 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 el 30 de Mayo de 2022
@Nudrat Sufiyan comment moved here
It means I should change the value of r2

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by