function [ ] = PlotI( data,M )
N = size(data,1);

Vd = data(:,1);
Id = data(:,2);
Vg = data(:,3);

KP = M(1);
VT0 = M(2); 
LAMBDA = exp(M(3));
RS = exp(M(4));
RD = exp(M(5));

Vds = Vd - Id.*(RS+RD);
Vgs = Vg - Id.*RS;

i = 1;
n = 1;
figure()

while i<=N
    if (n == 1) || (Vd(i) > Vd(i-1))
        I(n) = Id(i);
        V(n) = Vd(i);
    else
        plot(V,I);
        hold on
        V = 0;
        I = 0;
        n = 0;
        i = i - 1;
    end
    i = i + 1;
    n = n + 1;
end
plot(V,I);

V = 0;
I = 0;
i = 1;   
n = 1;
while i <= N
    if (n == 1) || (Vds(i) > Vds(i-1))
        if (Vds(i)) < (Vgs(i) - VT0)            %Linear region
            I(n) = KP*(Vgs(i) - VT0 - ((Vds(i))/2))*(Vds(i))*(1 + LAMBDA*Vds(i));
            V(n) = Vds(i);
        else                                %Saturation region
            I(n) = (KP/2)*((Vgs(i) - VT0)^2)*(1 + LAMBDA*Vds(i));
            V(n) = Vds(i);
        end
    else
        plot(V,I,'r')
        V = 0;
        I = 0;
        i = i - 1;
        n = 0;
    end
    i = i + 1;
    n = n + 1;
end
plot(V,I,'r')

xlabel('Vds [V]')
ylabel('Id [A]')
ylim([0 20])
xlim([0 5])
