function [fitresult, gof] = create_halo_fit(x, y, ploton,start)
%CREATEFITS(X,Y)
%  Create fits using generalized logisitic function.
%
%  Data for 'halo_fit' fit:
%      X Input : x
%      Y Output: y
%  Output:
%      fitresult : a cell-array of fit objects representing the fits.
%      gof : structure array with goodness-of fit info.
%
%  See also FIT, CFIT, SFIT.

%  Auto-generated by MATLAB on 09-May-2014 12:12:40

%% Initialization.

% Initialize arrays to store fits and goodness-of-fit.
% gof = struct( 'sse', cell( 2, 1 ), ...
%     'rsquare', [], 'dfe', [], 'adjrsquare', [], 'rmse', [] );

%% Fit: 'chr2_fit'.
[xData, yData] = prepareCurveData( x, y );

% Set up fittype and options.
ft = fittype( 'A*exp(-(x-B)/C)+D', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.Lower = [0 0 0 0];
opts.Robust = 'Bisquare';
opts.StartPoint = start;

% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );

if ploton
    % Plot fit with data.
    figure( 'Name', 'halo_fit' );
    h = plot(fitresult, xData, yData );
    legend( h, 'y vs. x', 'chr2_fit', 'Location', 'NorthEast' );
    % Label axes
    xlabel( 'x' );
    ylabel( 'y' );
    grid on
end


