% 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_296K);
V = diode_sort(:,1);
I = diode_sort(:,2);
f=1.602e-019/1.38e-023; 
% Initialize the coefficients of the function
X0=[.1,.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 = params(2)*exp(-f*params(1)/296)*(exp(f*V/296)-1);

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