% Define the data sets that you are trying to fit the
% function to.  Make sure to import these into MatLab before running this
diode_sort=sortrows(MJR_diode_12_03_200K);
V = diode_sort(:,1);
I = diode_sort(:,2);
f=1.602e-019/1.38e-023; 
% Initialize the coefficients of the function
X0=[1];
 
% Set an options file for LSQNONLIN to use the
% medium-scale algorithm
options = optimset('Largescale','off');
 
% Calculate the new coefficients using LSQNONLIN
[params,renorm]=lsqnonlin(@diodecomp_test,X0,[],[],options,V,I);
 
%define the fitted function
Y_fit = 3.3505e-013*params(1)*(exp(f*V/200)-1);

plot(V,Y_fit,'b+');
hold
plot(V,I,'ko');
hold