function [m,sstd]=pdffit2(data,W,color)
%DITFITTING    Create plot of datasets and fits
%   DITFITTING(data)
%   Creates a plot, similar to the plot in the main distribution fitting
%   window, using the data that you provide as input.  You can
%   apply this function to the same data you used with dfittool
%   or with different data.  You may want to edit the function to
%   customize the code and this help message.
%
%   Number of datasets:  1
%   Number of fits:  2

% This function was automatically generated on 18-Nov-2010 09:06:07
 
% Data from dataset "January":
%    Y = data
 
% Force all inputs to be column vectors
data = data(:);

% Set up figure to receive datasets and fits
% f_ = clf;
% figure(f_);
% set(f_,'Units','Pixels','Position',[97 166 614 423.925]);
% legh_ = []; legt_ = {};   % handles and text for legend
% ax_ = newplot;
% set(ax_,'Box','on');
% hold on;

% --- Plot data originally in dataset "January"
t_ = ~isnan(data);
Data_ = data(t_);
[F_,X_] = ecdf(Data_,'Function','cdf'...
              );  % compute empirical cdf
Bin_.rule = 5;
Bin_.width = W;
Bin_.placementRule = 1;
[C_,E_] = dfswitchyard('dfhistbins',Data_,[],[],Bin_,F_,X_);
[N_,C_] = ecdfhist(F_,X_,'edges',E_); % empirical pdf from cdf
h_ = bar(C_,N_,'hist');
set(h_,'FaceColor',color,'FaceAlpha',0.5,'EdgeColor',color,...
       'LineStyle','-', 'LineWidth',1.1);
% 'facealpha',0.5,'edgealpha',0.5); %sets transparency but doesn't
        %print well
%ylabel('Probability Density','fontsize',14);

% xlim([-6 6])
% ylim([0 0.35])
% % legh_(end+1) = h_;
% % legt_{end+1} = 'Data';

% Nudge axis limits beyond data limits
% %xlim_ = get(ax_,'XLim');
% if all(isfinite(xlim_))
%    xlim_ = xlim_ + [-1 1] * 0.01 * diff(xlim_);
%    %set(ax_,'XLim',xlim_)
% end
% 
% x_ = linspace(xlim_(1),xlim_(2),100);

hold on;

% Compute 1st and 2nd moments:
m=nanmean(data);
sstd=nanstd(data);

% % Create textbox
% annotation(gcf,'textbox',[0.716 0.7948 0.1635 0.1108],...
%     'String',{['mean= ',num2str(m,'%6.2f' ),' std=  ',num2str(sstd,'%6.2f' )]},...
%     'FontSize',12,'EdgeColor',color,'Color',color,'LineWidth',1.1,...
%     'FitBoxToText','off');

