function plotyy2(varargin);
%plotyy2(X1,Y1,style1,X2, Y2, style2, fignum); %input with figure number
%plotyy2(X1,Y1,style1,X2, Y2, style2); %input without figure number
%plotyy2(X1,Y1,style1,label1,X2, Y2, style2,label2, fignum); %input with
%figure number and axis label
%plotyy2(X1,Y1,style1,label1,X2, Y2, style2, label2); %input without figure number but
%title


if nargchk(6, 9, nargin);
  error('Check input arguments - must have between 6 and 9')
end

%set default figure number
fignum=1;

%  Get inputs

X1 = varargin{1};
Y1 = varargin{2};

if nargin == 6 | nargin ==7
    style1 = varargin{3};
    X2 = varargin{4};
    Y2 = varargin{5};
    style2 = varargin{6};
else
    style1 = varargin{3};
    label1 = varargin{4};
    X2 = varargin{5};
    Y2 = varargin{6};
    style2 = varargin{7};
    label2 = varargin{8};
end

if nargin ==7
    fignum = varargin{9};
end

if nargin == 9
    fignum = varargin{9};
end



%adds style to plotyy
figure(fignum); 
[AX,H1,H2] = plotyy(X1,Y1,X2,Y2);

if nargin>7
    set(get(AX(1),'Ylabel'),'String',label1, 'Color', char(style1(1,1)), 'FontSize', 20) %sets the labels
    set(AX(1),'XColor',char(style1(1,1)),'YColor',char(style1(1,1)), 'FontSize', 20)
    
 
    set(get(AX(2),'Ylabel'),'String',label2, 'Color', char(style2(1,1)), 'FontSize',20)
    set(AX(2),'XColor',char(style2(1,1)),'YColor',char(style2(1,1)), 'FontSize', 20)
    
    
end

if length(style1) >= 2
   set(H1,'LineStyle',char(style1(1,2:length(style1))), 'Color', char(style1(1,1)), 'LineWidth', 2)
else
   set(H1,'Color', char(style1(1,1)), 'LineWidth', 2)
end

if length(style2) >= 2
   set(H2,'LineStyle',char(style2(1,2:length(style2))), 'Color', char(style2(1,1)), 'LineWidth', 2)
else
   set(H2,'Color', char(style2(1,1)), 'LineWidth', 2)
end




