www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@mbcgraph/@legend/refresh.m

    function refresh(obj, varargin)
%REFRESH Update the legend
%
%  REFRESH(OBJ, HITEMS) recreates legend items for each item handle in
%  HITEMS. They are labelled with a set of default strings.
%
%  REFRESH(OBJ, HITEMS, LABELS) recreates the legend items with the given
%  set of labels.  LABELS must be the same length as HITEMS.
%
%  REFRESH(OBJ, LABELS) replaces the current legend labels with the new
%  labels.

%  Copyright 2000-2013 The MathWorks, Inc. and Ford Global Technologies, Inc.

% Decide what input mode is used
if nargin<2
    error(message('mbc:mbcgraph:legend:InvalidArgument'));
end

if nargin==3
    hItems = varargin{1};
    sLabels = varargin{2};
else
    if ischar(varargin{1}) || iscell(varargin{1})
        sLabels = varargin{1};
        [hItems, ~] = curvefitlib.internal.getLegendItems(obj.Parent);
    else
        hItems = varargin{1};
        sLabels = {};
    end
end

% Check that the parent is constant - we do not support altering the parent
if ~isempty(hItems)
    hAxes = get(hItems(1), 'Parent');
    if hAxes~=obj.Parent
        error(message('mbc:mbcgraph:legend:InvalidArgument1'));
    end
end
obj.pGenLegend(hItems, sLabels);
end