function figure1 = make_err_plot(XMatrix, YMatrix, EMatrix, names, caption, legendpos, notit, xlimit, ...
				 ylimit, vertlines, xtick, ytick)% CREATEFIGURE(XMATRIX1,YMATRIX1,EMATRIX1)
%  XMATRIX1:  errorbar x matrix
%  YMATRIX1:  errorbar y matrix
%  EMATRIX1:  errorbar e matrix

%  Auto-generated by MATLAB on 09-Nov-2010 09:39:25

%  Create figure

tit = caption.tit;
xl = caption.xlabel;
yl = caption.ylabel;

figure1 = figure('XVisual',...
    '0x12c (TrueColor, depth 24, RGB mask 0xff0000 0xff00 0x00ff)',...
    'Name', tit, 'Position', [0 0 620 480]);

% Create axes
axes1 = axes('Parent',figure1,'YGrid','on', 'FontSize', 16);

% Uncomment the following line to preserve the X-limits of the axes
if ~exist('xlimit')
  if (~iscell(XMatrix))
    xlim(axes1,[10-1 50+1]);
  else
    xlim(axes1,[-.025 1.025]);
  end
else
  if ~isempty(xlimit)
    xlim(xlimit)
  end
end

if ~exist('ytick') || isempty(ytick)
  set(axes1,'YTick', [0:.1:1]);
  set(axes1,'YTickLabel', ['  0'; '   '; '0.2'; '   '; '0.4'; '   '; '0.6'; '   '; '0.8'; '   '; '  1']);
else
  set(gca,'YTICK', ytick);
end

% if ~exist('xtick') || isempty(xtick)
%   set(axes1,'XTick', [0:.2:1]);
% else
%   set(axes1,'XTick', xtick);
% end

% Uncomment the following line to preserve the Y-limits of the axes

if ~exist('ylimit')
    ylim(axes1,[-.025 1.025]);
else
  if (~isempty(ylimit))
    ylim(ylimit);
  end
end

box(axes1, 'on');
hold(axes1, 'all');

xlabel(xl, 'fontsize', 23);
ylabel(yl, 'fontsize', 23);
% Create multiple error bars using matrix input to errorbar

colors=[1 0 0
	0 0 1
	0 .6 0
	1 .3 1
	0 0 0
        1 .6 0
        1 0 0];

if (~iscell(XMatrix))
  errorbar1 = errorbar(XMatrix(:,:), YMatrix(:,:), EMatrix(:,:), 'LineWidth', 3);
  set(errorbar1(1), 'DisplayName', names{1}, 'LineWidth', 3, 'Color', colors(1,:));
  if (numel(errorbar1) > 1)
    set(errorbar1(2), 'DisplayName', names{2}, 'LineWidth', 3, 'Color', colors(2,:));
  end
  if (numel(errorbar1) > 2)
    set(errorbar1(3), 'DisplayName', names{3}, 'LineWidth', 3, 'Color', colors(3,:));
  end
  if (numel(errorbar1) > 3)
    set(errorbar1(4), 'DisplayName', names{4}, 'LineWidth', 3, 'Color', colors(4,:));
  end
  if (numel(errorbar1) > 4)
    set(errorbar1(5), 'DisplayName', names{5}, 'LineWidth', 3, 'Color', colors(5,:));
  end
else

  for i=1:numel(XMatrix)
    myplot(i) = plot(XMatrix{i}, YMatrix{i}, 'LineWidth', 3);
    set(myplot(i), 'DisplayName', names{i}, 'LineWidth', 3, 'Color', colors(i,:));
    if (i == 7)% || i == 4)
      set(myplot(i), 'LineStyle', '--');
    end    
  end
  
  if ~isempty(EMatrix)
    for j=1:numel(XMatrix)
      n(j) = numel(XMatrix{j});
      for i=[1:floor(n(j)/10):n(j)-n(j)/10 n(j)]
	e = errorbar(XMatrix{j}(i), YMatrix{j}(i), EMatrix{j}(i), 'Color', colors(j,:), 'LineWidth', 2);
	hAnnotation = get(e, 'Annotation');
	hLegendEntry = get(hAnnotation', 'LegendInformation');
	set(hLegendEntry, 'IconDisplayStyle', 'off')
      end
    end
  end
end


%plot1 = plot(XMatrix1(:,4), YMatrix1(:,4), 'LineWidth', 3);
%set(plot1, 'DisplayName', 'SH', 'Color', [0 0.7 0]);

% Create legend
legend1 = legend(axes1,'show');
if (strcmp(legendpos, 'br'))
  set(legend1, 'Location', 'SouthEast');
elseif (strcmp(legendpos, 'tr'))
  set(legend1, 'Location', 'NorthEast');
end

% set(legend1,'FontSize', 19);

if (~exist('notit') || (exist('notit') && ~notit))
  title({tit, ''}, 'fontsize', 15);
end

if (exist('vertlines'))
  for i=1:numel(vertlines)
    myline(i) = line([vertlines(i) vertlines(i)], [0 1]);
    set(myline(i), 'LineStyle', '--');
    set(myline(i), 'Color', [0 0 0]);
  end
end


