# I have a problem with my plot. I need to plot one curve for every value of the matrix "Vgs", but i need all the curves in one graphic (and considering the conditions)

1 view (last 30 days)
Felipe Evangelista on 30 Jul 2022
Answered: Voss on 30 Jul 2022
hold on
clear
k = 1
Vt = 0.6
L = 0.01
Vds = linspace(0,5,200)
Vgs = [0.5 1 1.5 2 2.5 3]
color = ['-r' '-b' '-g' '-c' '-y' '-k']
for i = 1:6
if Vds < (Vgs(1,i) - Vt)
Id = k*((Vgs(1,i) - Vt)*Vds - (1/2)*(Vds^2))*(1 + L*Vds)
elseif Vds >= (Vgs(1,i)- Vt)
Id = (k/2)*((Vgs(1,i) - Vt)^2)*(1 + L*Vds)
end
plot(Vds,Id,color(1,i))
end
hold off
xlabel('Vds (V)')
ylabel('Coorrente de dreno (mA)')
title('Corrente de dreno X Vds')
Data: k = 1 mA/V2, Vt = 0,6 V and L = 0,01 V^-1, plot one graphic with the values of Id in function of Vds, for Vds between 0 and 5V, and Vgs with the values: 0,5 V; 1,0 V;1,5 V; 2,0 V; 2,5 V and 3,0 V.
##### 1 CommentShowHide None
Felipe Evangelista on 30 Jul 2022
The code above is the one that i made, but that's wrong.

Voss on 30 Jul 2022
hold on
clear
k = 1; % use semi-colons to suppress command-line output
Vt = 0.6;
L = 0.01;
Vds = linspace(0,5,200);
Vgs = [0.5 1 1.5 2 2.5 3];
% character array (not useful for what you want to do with it)
color = ['-r' '-b' '-g' '-c' '-y' '-k']
color = '-r-b-g-c-y-k'
% cell array of character vectors (would work)
color = {'-r' '-b' '-g' '-c' '-y' '-k'}
color = 1×6 cell array
{'-r'} {'-b'} {'-g'} {'-c'} {'-y'} {'-k'}
% string array also works
color = ["-r" "-b" "-g" "-c" "-y" "-k"]
color = 1×6 string array
"-r" "-b" "-g" "-c" "-y" "-k"
% initialize Id as a vector of zeros the size of Vds:
Id = zeros(size(Vds));
for i = 1:numel(Vgs)
% idx is a logical (true/false) vector, saying whether Vds is less than Vgs(1,i) - Vt
idx = Vds < Vgs(1,i) - Vt;
% use logical indexing to populate the elements of Id using the two equations:
Id(idx) = k*((Vgs(1,i) - Vt)*Vds(idx) - (1/2)*(Vds(idx).^2)).*(1 + L*Vds(idx));
Id(~idx) = (k/2)*((Vgs(1,i) - Vt).^2).*(1 + L*Vds(~idx));
plot(Vds,Id,color(1,i))
end
hold off
xlabel('Vds (V)')
ylabel('Coorrente de dreno (mA)')
title('Corrente de dreno X Vds') References: