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

%   Copyright 1984-2022 The MathWorks, Inc.

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

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

if isempty(label)
    label = '';
end

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