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

%   Copyright 1984-2022 The MathWorks, Inc.

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

% Chart subclass support
% Invoke ylabel 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 = ylabel(targets, label, nvPairs{:});
    else
        ylabel(targets, label, nvPairs{:});
    end
    return
end

if isempty(label)
    label = '';
end

if isscalar(targets) && isappdata(targets,'MWBYPASS_ylabel')
    % Allow Control System Toolbox to overload the ylabel command.
    h = mwbypass(targets, 'MWBYPASS_ylabel', label, nvPairs{:});
else
    h = reshape([targets.YLabel], 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
