% Enter data within the brackets and uncomment the variables

If1=[ ]; % Enter increasing field current data as a row array  
E1 =[ ]; % Enter corresponding E data for increasing If1 
If2=[ ]; % Enter decreasing field current data as a row array
E2 =[ ]; % Enter corresponding E data for decreasing If
n= 2;                   % n is polynomial order, if necessary change n to  
                        % 3rd or higher to obtain a satisfactory curve  
c1=polyfit(If1, E1,n);  % Returns polynomial coefficients for increasing If1   
c2=polyfit(If2, E2,n);  % Returns polynomial coefficients for decreasing If2 
E1fit=polyval(c1, If1); % Evaluates the polynomial values for array If1
E2fit=polyval(c2, If2); % Evaluates the polynomial values for array If2
plot(If1, E1, 'xr', If2, E2, 'ob', If1, E1fit, 'r',  If2, E2fit, 'b' )
title('DC Generator Magnetization curve')
xlabel('I_f, Amps'), ylabel('E, Volts')
legend('Increasing I_f', 'Decreasing I_f', 4)