How to plot all rows of an array with a random color
38 views (last 30 days)
Show older comments
Hello there,
i am working on I-V charchteristics of a mosfet script
My Proplem is : i need to plot all the rows of the generated array called current2 " Dynamic Size " => depends on user inputs
and i need it to be in a random color for each line
+
How to generate a keymap to read the plot ?
sample input :
1- mobility of electrons : 80
2- thickness of oxide : 10.5*10^-8
3- W/L : 2
4 threshold voltage : 0.3
5- vgs = 0 - 1 - 10
output will be like this
this is the script :
% Long-Channel I-V Characteristics
clc
clear all
%Mobility of Electrons
un=input('Please enter the mobility of electrons ( c𝑚2/𝑉s ) : ');
disp('------------------------------------------------------')
%Thickness of Oxide
tox = input('Please enter the thickness of oxide ( meter ) : ');
disp('------------------------------------------------------')
%The Ratio Between Width & Length of Transistor
w_L=input('Please enter the value of W / L : ');
disp('------------------------------------------------------')
%Threshold Voltage
Vth=input('Please enter the threshold voltage ( volt ) :');
disp('------------------------------------------------------')
%vgs=input('Please enter the Vgs value in volts : ');
vgsstart =input('Please Define the start of Vgs values : ');
disp('------------------------------------------------------')
vgsstep =input('Please Define the step between each value of Vgs values : ');
disp('------------------------------------------------------')
vgsend =input('Please Define the end of Vgs values : ');
%Sweep drain to source voltge from vdsstart to vdsend & each step is vdsstep
vds=vgsstart:vgsstep:vgsend;
%Defining the Vgs Values
vgs=vgsstart:vgsstep:vgsend;
%calculating cox & un*cox "kn"
cox=3.9*8.854*10^-14/tox;
kn=un*cox;
%calculating Beta
beta=kn*w_L;
%Estimate length of the array Vds
m=length(vds);
%Estimate length of the array Vgs
n=length(vgs);
%Calulating Ids
for x=1:n
for i=1:m
%Cutoff Region
if vgs(x) < Vth
current2(x,i)=0;
%Linear Region
elseif vds(i) < (vgs(x) - Vth)
current2(x,i)=beta*((vgs(x)-Vth)*vds(i) - 0.5*(vds(i)^2));
%Saturation Region
elseif vds(i) >= (vgs(x) - Vth)
current2(x,i)=0.5* beta * ((vgs(x) - Vth)^2);
end
end
end
%Plotting the I-V Characteristics
plot(vds,current2(2,:),'y',vds,current2(3,:),'b',vds,current2(4,:),'g',vds,current2(5,:),'r')
xlabel('Vds, V')
ylabel('Ids,A')
title('Ids-Vds Characteristics of a N-Mos')
0 Comments
Answers (1)
Image Analyst
on 21 Dec 2021
Edited: Image Analyst
on 21 Dec 2021
If you want a random color for each line, get a random color (1 1-by-3 array between 0 and 1) for each line
for k = 2 : 5
plot(vds,current2(k,:), '-', 'Color', rand(1, 3), 'LineWidth', 3);
hold on;
end
hold off;
If you want specific colors
myColors = {'k', 'r', 'g', 'b', [0.4, 0.2, 0.7], 'm'}; % Specify specific colors
for k = 2 : 5
plot(vds,current2(k,:), '-', 'Color', myColors{k}, 'LineWidth', 3);
hold on;
end
hold off;
2 Comments
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!