function hh = xlabel(varargin)
%XLABEL X-axis label.
%   XLABEL('text') adds text beside the X-axis on the current axis.
%
%   XLABEL('text','Property1',PropertyValue1,'Property2',PropertyValue2,...)
%   sets the values of the specified properties of the xlabel.
%
%   XLABEL(AX,...) adds the xlabel to the specified axes.
%
%   H = XLABEL(...) returns the handle to the text object used as the label.
%
%   See also YLABEL, ZLABEL, TITLE, SUBTITLE, TEXT.

%   Copyright 1984-2022 The MathWorks, Inc.

% Parse the inputs and validate the target.
[targets, label, nvPairs] = labelcheck('XLabel',varargin);
label = label{1};

% Chart subclass support
% Invoke xlabel method with same number of outputs to defer output arg
% error handling to the method.
if isa(targets,'matlab.graphics.chart.Chart')
    if(nargout == 1)
        hh = xlabel(targets, label, nvPairs{:});
    else
        xlabel(targets, label, nvPairs{:});
    end
    return
end

if isempty(label)
    label = '';
end

if isscalar(targets) && isappdata(targets,'MWBYPASS_xlabel')
    % Allow Control System Toolbox to overload the xlabel command.
    h = mwbypass(targets, 'MWBYPASS_xlabel', label, nvPairs{:});
else
    h = reshape([targets.XLabel], size(targets));
    if ~isa(targets,'matlab.graphics.layout.Layout')
        set(h,'FontSizeMode','auto',...
            'FontUnitsMode','auto',...
            {'FontWeight'},{targets.FontWeight}',...
            {'FontAngle'},{targets.FontAngle}',...
            {'FontName'},{targets.FontName}');
    end

    try
        set(h, 'String', label, nvPairs{:});
    catch ex
        throw(ex);
    end
end

if nargout > 0
    hh = h;
end
