function l = plotItem(l, msgId, X, Y, varargin)
%PLOTITEM add name to legend only when X, Y actually adds a series.
%
% This function is for internal use only.

%   Copyright 2011-2013 The MathWorks, Inc.

  if ~((isempty(X) || all(isnan(X))) && (isempty(Y) || all(isnan(Y))))
    h = plot(X, Y, varargin{:});
    l(1,end+1) = {getString(message(msgId))};
    l(2,end) = {h};
  end
end