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 ビュー (過去 30 日間)
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 件のコメント
Felipe Evangelista
Felipe Evangelista 2022 年 7 月 30 日
The code above is the one that i made, but that's wrong.

サインインしてコメントする。

回答 (1 件)

Voss
Voss 2022 年 7 月 30 日
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:

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by