www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/+mbcmodelview/@OutlierLine/add.m
function add(obj, newH) %ADD Add lines to the outlier set. % % ADD(OL, NEWHANDLES) % checks NEWHANDLES are line handles and adds them to the outlierline OL % Copyright 2000-2015 The MathWorks, Inc. and Ford Global Technologies, Inc. newH = isLineHandle(obj, newH); % only want truly new lines newH = setdiff(newH, obj.lineHandles); if isempty(newH) return else % Set ButtonDownFcn for the new lines set(newH,'ButtonDownFcn',{@i_lineClick,obj}); olIndex = obj.outlierIndices; newAx = get(newH, {'Parent'}); newAx = [newAx{:}]; newOL= gobjects(1,length(newH)); % do the drawing on the new lines labelled by newH for i = 1:length(newH) xdata= get(newH(i),'XData'); ydata= get(newH(i),'YData'); zdata= get(newH(i),'ZData'); % only plot the points that can be displayed on this line thisIndex=unique(olIndex(olIndex<= length(xdata))); oLxdata= xdata(thisIndex); oLydata= ydata(thisIndex); if isempty(zdata) || isscalar(zdata) % copy zdata oLzdata = zdata; else oLzdata= zdata(thisIndex); end if isempty(oLxdata) oLxdata= NaN; oLydata= NaN; oLzdata= NaN; end newOL(i) = line('XData',oLxdata,... 'YData',oLydata,... 'ZData',oLzdata,... 'Color',obj.Color,... 'Marker',obj.Marker,... 'LineStyle','none',... 'Parent',newAx(i),... 'Tag','Outliers',... 'MarkerSize',obj.MarkerSize,... 'LineWidth',obj.LineWidth); mbcgui.hgclassesutil.setNotPickable(newOL(i)); xregGui.setLegendData(newOL(i), 'Outliers'); end % set the userdata fields obj.LineHandles = [obj.LineHandles(:); newH(:) ]; obj.OutlierLines = [obj.OutlierLines(:); newOL(:) ]; obj.LineParents = [obj.LineParents(:); newAx(:)]; % listen for line being destroyed L_LineDestroyed = cell(1,length(newH)); newLx= cell(1,length(newH)); newLy= cell(1,length(newH)); for i=1:length(newH) L_LineDestroyed{i} = mbcgui.hgclassesutil.listener(newH(i), .... 'ObjectBeingDestroyed', mbcutils.callback(@i_lineDestroyed, obj)); % listen for xdata being changed newLx{i} = mbcgui.hgclassesutil.proplistener(newH(i), 'XData', 'PostSet', ... mbcutils.callback(@i_dataResize, obj)); % listen for ydata being changed newLy{i} = mbcgui.hgclassesutil.proplistener(newH(i), 'YData', 'PostSet', ... mbcutils.callback(@i_dataResize, obj)); end obj.L_LineDestroyed = [obj.L_LineDestroyed L_LineDestroyed]; % store new listeners in OL obj obj.L_DataChanging = [obj.L_DataChanging [newLx ; newLy]]; end function i_lineDestroyed(src, ~, obj) % the line handle = double(src) remove(obj, mbcgui.hgclassesutil.toNative(src)); function i_lineClick(lineH, ~, obj) hFig = ancestor(lineH, 'figure'); clicktype= get(hFig,'SelectionType'); switch clicktype case 'alt' if iscell(obj.AltClickCallback) funcHand = obj.AltClickCallback{1}; feval(funcHand,lineH,[],obj.altClickCallback{2:end}); elseif isa(obj.AltClickCallback,'function_handle') obj.AltClickCallback(lineH,[]); elseif ischar(obj.AltClickCallback) % it is a string eval(obj.AltClickCallback); end otherwise click(obj, lineH); end function i_dataResize(~, event, obj) hLine = event.AffectedObject; if length(get(hLine, 'XData'))==length(get(hLine, 'YData')) redraw(obj); end