Follow Me On...

Matlab Snippits

I can never seem to remember all the syntax in Matlab. So, here i’m going to post matlab snippits (whenever i use matlab) which could be modified for your own use.

Example 1 - Plotting mulitple functions on a single graph

% constants from table 6.2
KPn = 120e-6;
W = 3e-6
L = 1e-6
Vthn = 0.8;
lambda = 0.01;

Vds = [0:0.01:5];

for Vgs = 1:5
	Vdssat = Vgs - Vthn;
	IdSat(Vgs,:) = KPn/2*W/L*(Vgs-Vthn)^2*
                       (1+lambda*(Vds(1,:)-Vdssat));
	IdTri(Vgs,:) = KPn*W/L*((Vgs-Vthn)*Vds(1,:) - 
                       (Vds(1,:).^2)/2);

	for i = 1:length(Vds)
		if Vds(i)<=(Vgs - Vthn)
			Id(Vgs,i)=IdTri(Vgs,i);
		else
			Id(Vgs,i)=IdSat(Vgs,i);
	end
end

plot (Vds(1,:), Id(Vgs,:),’b’)
hold on
end
title(‘Characteristics of a long-channel NMOS device’);
xlabel(‘Vds (V)’);
ylabel(‘Id (A)’);
grid;