MATLAB help

Thread Starter

vustudent

Joined Mar 11, 2009
38
I am trying to plot Vgs versus Id, the problem is when Vgs < Vth , Id should be zero, and I have problem in assigning Id to be 0 for the condition Vgs < Vth.


Rich (BB code):
% Problem 1 A)
 Vgs = [0 : 0.01 :1.2]; Vth = 250e-3; Vds = 1.2;

% Vds > Vgs - Vth ,  transistor in saturation

uCox = 370e-6; lamda = 0.1; W = 5; L = 1;

Id = 1/2 .*uCox .*W/L .*(Vgs - Vth).^2;


for (Vgs < Vth)
    Id(1) = 0
    ++Id;
end



plot(Vgs,Id);
 
Last edited:

Thread Starter

vustudent

Joined Mar 11, 2009
38
put if rather than for (for for repeating not condition)

Rich (BB code):

if (Vgs<Vth)
Id(1) = 0;
++Id;
end

I did that but still Id isn't being assigned to be zero for the range of Vgs < Vth,
I need to find a way to renew the Id matrix to be zero when Vgs < Vth
 

Thread Starter

vustudent

Joined Mar 11, 2009
38
I also tried this, but I got Id to be all zeros


Rich (BB code):
% Problem 1 A)

 Vgs = [0 : 0.01 :1.2]; Vth = 250e-3; Vds = 1.2;

% Vds > Vgs - Vth ,  transistor in saturation

uCox = 370e-6; lamda = 0.1; W = 5; L = 1;


if (Vgs > Vth)
Id = 1/2 .*uCox .*W/L .*(Vgs - Vth).^2;
else 
Id = 0; 
end

plot(Vgs,Id);
 

Thread Starter

vustudent

Joined Mar 11, 2009
38
I guess I could manually assign Id to be zero using a for loop, seems cheating though, just no idea what's wrong with my previous attempts, matlab is just different from C

Rich (BB code):
% Problem 1 A)

 Vgs = [0 : 0.01 :1.2]; Vth = 250e-3; Vds = 1.2;

% Vds > Vgs - Vth ,  transistor in saturation

uCox = 370e-6; lamda = 0.1; W = 5; L = 1;


Id = 1/2 .*uCox .*W/L .*(Vgs - Vth).^2;

for a = 1:25
    Id(a) =0;
end



plot(Vgs,Id);
 

johndoe45

Joined Jan 30, 2010
364
Vgs = [0 : 0.01 :1.2]; Vth = 250e-3; Vds = 1.2;

% Vds > Vgs - Vth , transistor in saturation

uCox = 370e-6; lamda = 0.1; W = 5; L = 1;

Id = 1/2 .*uCox .*W/L .*(Vgs - Vth).^2;

for i=1:length(Vgs)

if Vgs(i) < Vth
Id(i) = 0;
++Id;
end

end

plot(Vgs,Id);
 
Top