function varargout = rfplot(varargin) 
%RFPLOT Plot S-parameter Data
%   RFPLOT(S_OBJ) plots the magnitude in dB versus frequency of all
%   possible S-parameters (S11, S21, ..., Snn) on the current axis. S_OBJ
%   must be an sparameters object.
%
%   RFPLOT(S_OBJ,I,J) plots the magnitude in dB of one specific S-parameter
%   (Sij) on the current axis. I and J must be positive integers whose
%   value is less than or equal to the number of ports represented by
%   S_OBJ.
%
%   RFPLOT(S_OBJ,[I1.. In],[J1... Jm]) plots the magnitude in dB of
%   specified S-parameters (SI1J1 through SInJm combinations) on the
%   current axis. I and J must be positive integers whose value is less
%   than or equal to the number of ports represented by S_OBJ.
%
%   RFPLOT(S_OBJ,{[I1 J1];...;[In Jn]}) plots the magnitude in dB of
%   specified S-parameters (SI1J1 ... SInJn) on the current axis. I and J
%   must be positive integers whose value is less than or equal to the
%   number of ports represented by S_OBJ.
%
%   RFPLOT(S_OBJ,LINESPEC) and RFPLOT(S_OBJ,I,J,LINESPEC) allow the user to
%   specify a standard Line Specification to control the appearance of the
%   plot.
%
%   RFPLOT(S_OBJ,PLOTFLAG) and RFPLOT(S_OBJ,I,J,PLOTFLAG) allow the user to
%   specify the type of plot they wish to create.  Valid PLOTFLAGs are 'db'
%   (default), 'real', 'imag', 'abs', 'angle'.
%
%   RFPLOT(S_OBJ,'diag') and RFPLOT(S_OBJ,'diag',PLOTFLAG) allow the user
%   to plot Sii, reflection coefficients.
%
%   RFPLOT(S_OBJ,PART) and RFPLOT(S_OBJ,PART,k) plots upper or lower
%   triangular part of the S-parameters matrix. Valid PARTs are 'triu' and
%   'tril'. Using k (default k=0), returns the elements on and above/below
%   the kth diagonal of S-parameters matrix. See triu and tril for more
%   information.
%   
%   RFPLOT(RFBUDGETOBJ,ANALYSISFLAG) plots the one-tone or two-tone
%   analysis of an rfbudget object given Harmonic Balance results have been
%   calculated and are available. ANALYSISFLAG can take values 'OneTone'
%   or 'TwoTone'.
%
%   RFPLOT(ax,___) plots in the axes specified by ax instead of in the
%   current axes (gca). The option ax can precede any of the input argument
%   combinations in the previous syntaxes. Target axes, ax, is specified as
%   an Axes or an UIAxes.
%
%   H = RFPLOT(...) returns a column vector of handles to the line objects,
%   where H contains one handle per line plotted.
%
%EXAMPLES:
%   % Read in the file 'default.s2p' into an sparameters object
%   S = sparameters('default.s2p');
%
%   % Plot all 4 of the parameters using RFPLOT
%   rfplot(S)
%   
%   % Plot S21 in dB
%   rfplot(S,2,1)
%
%   % Plot the angle of S21 in degrees
%   rfplot(S,2,1,'angle')
%
%   See also sparameters, rfparam, setrfplot, rfinterp1, smithplot,
%   rfbudget/rfplot, rffilter/rfplot, matchingnetwork/rfplot, triu, tril

%   Copyright 2012-2022 The MathWorks, Inc.

narginchk(1,Inf)

if nargin >= 2 && isa(varargin{2},'rfbudget')
    narginchk(2,4)
    rfplot(varargin{2:end},'Parent',varargin{1})
elseif nargin >= 2 && (isa(varargin{2},'rffilter') || isa(varargin{2},'lcladder')...
        || isa(varargin{2},'amplifier'))
    narginchk(2,4)
    nargoutchk(0,2)
    % if isa(varargin{2},'amplifier')
    %     if nargin == 3
    %         rfplot(varargin{2:end},varargin{3},'Parent',varargin{1});
    %     else
    %         rfplot(varargin{2:end},'PowerCharacteristics','Parent',varargin{1});
    %     end
    % end
    if nargout
        [varargout{1}, varargout{2}] = rfplot(varargin{2:end},'Parent',varargin{1});
    
    else
        rfplot(varargin{2:end},'Parent',varargin{1});
    end
elseif nargin >= 2 && isa(varargin{2},'sparameters')
    narginchk(2,6)
    nargoutchk(0,1)
    if nargout
        varargout{1} = rfplot(varargin{2:end},'Parent',varargin{1});
    else
        rfplot(varargin{2:end},'Parent',varargin{1});
    end
elseif nargin >= 2 && isa(varargin{2},'mixerIMT')
    narginchk(2,8)
    nargoutchk(0,2)
    if nargout
        varargout{1} = rfplot(varargin{2:end},'Parent',varargin{1});
    else
        rfplot(varargin{2:end},'Parent',varargin{1});
    end
else
    error(message('MATLAB:UndefinedFunctionTextInputArgumentsType','rfplot',class(varargin{1})))
end
