# MATLAB help

Discussion in 'Programmer's Corner' started by vustudent, Sep 17, 2010.

1. ### vustudent Thread Starter Active Member

Mar 11, 2009
38
0
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.

Code ( (Unknown Language)):
1. % Problem 1 A)
2.  Vgs = [0 : 0.01 :1.2]; Vth = 250e-3; Vds = 1.2;
3.
4. % Vds > Vgs - Vth ,  transistor in saturation
5.
6. uCox = 370e-6; lamda = 0.1; W = 5; L = 1;
7.
8. Id = 1/2 .*uCox .*W/L .*(Vgs - Vth).^2;
9.
10.
11. for (Vgs < Vth)
12.     Id(1) = 0
13.     ++Id;
14. end
15.
16.
17.
18. plot(Vgs,Id);
19.
20.

Last edited: Sep 17, 2010
2. ### Eng_Bandar Active Member

Feb 27, 2010
50
1
put if rather than for (for for repeating not condition)

Code ( (Unknown Language)):
1. [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]
2. if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (Vgs<Vth)
3. Id(1) = 0;
4. ++Id;
5. [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]end
6. [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]

3. ### vustudent Thread Starter Active Member

Mar 11, 2009
38
0

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

4. ### vustudent Thread Starter Active Member

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

Code ( (Unknown Language)):
1.
2.
3. % Problem 1 A)
4.
5.  Vgs = [0 : 0.01 :1.2]; Vth = 250e-3; Vds = 1.2;
6.
7. % Vds > Vgs - Vth ,  transistor in saturation
8.
9. uCox = 370e-6; lamda = 0.1; W = 5; L = 1;
10.
11.
12. if (Vgs > Vth)
13. Id = 1/2 .*uCox .*W/L .*(Vgs - Vth).^2;
14. else
15. Id = 0;
16. end
17.
18. plot(Vgs,Id);

5. ### vustudent Thread Starter Active Member

Mar 11, 2009
38
0
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

Code ( (Unknown Language)):
1.
2. % Problem 1 A)
3.
4.  Vgs = [0 : 0.01 :1.2]; Vth = 250e-3; Vds = 1.2;
5.
6. % Vds > Vgs - Vth ,  transistor in saturation
7.
8. uCox = 370e-6; lamda = 0.1; W = 5; L = 1;
9.
10.
11. Id = 1/2 .*uCox .*W/L .*(Vgs - Vth).^2;
12.
13. for a = 1:25
14.     Id(a) =0;
15. end
16.
17.
18.
19. plot(Vgs,Id);
20.
21.

6. ### johndoe45 Member

Jan 30, 2010
364
1
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);