www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgtools/@lookup2editor/update.m
function update(obj) %UPDATE Called when table data has changed % % UPDATE(OBJ) is called to update the display after the obejct has been % changed. % Copyright 2000-2013 The MathWorks, Inc. and Ford Global Technologies, Inc. if isempty(obj.TablePtr) || isnull(obj.TablePtr) || obj.TablePtr.isempty colName = ''; rowName = ''; v = []; colBreakpoints = []; rowBreakpoints = []; locks = []; extrap = []; region = []; else tbl = obj.TablePtr.info; % Values v = get(tbl, 'values'); % Breakpoints pRowNorm = get(tbl, 'y'); pColNorm = get(tbl, 'x'); rowNorm = pRowNorm.info; colNorm = pColNorm.info; rowBreakpoints = invert(rowNorm, (0:size(v,1)-1)'); colBreakpoints = invert(colNorm, (0:size(v,2)-1)'); % Input name. If the immediate input to the table is a source, use % it's name. Otherwise use a generic "Breakpoints" label. pRowInp = get(rowNorm, 'x'); pColInp = get(colNorm, 'x'); if pRowInp.issource rowName = pRowInp.getname; else rowName = 'Y Breakpoints'; end if pColInp.issource colName = pColInp.getname; else colName = 'X Breakpoints'; end % Value locks locks = logical(get(tbl, 'vlocks')); if isempty(locks) locks = false(size(v)); end % extrapolation mask extrap = getExtrapolationMask(tbl); region = getExtrapolationRegions(tbl); end % Start table update if isempty(v) obj.Table.Peer.clearTable; Selected = zeros(0,2); else old_sel = obj.Table.getSelectedRegions; lims = mbcmakelimits(v); obj.Table.Peer.setColorRange(lims(1),lims(2)); obj.Table.Peer.setTableData(v, colBreakpoints, rowBreakpoints, locks, extrap, region); obj.Table.Peer.setCornerLabels(rowName,colName); for n = 1:size(old_sel, 1) obj.Table.addSelectedRegion(old_sel{n,1}(1), ... old_sel{n,2}(1), ... old_sel{n,1}(2)-old_sel{n,1}(1)+1, ... old_sel{n,2}(2)-old_sel{n,2}(1)+1); end [R,C]=ndgrid(obj.Table.getSelectedRows, obj.Table.getSelectedColumns); Selected = [R(:),C(:)]; end if obj.RightHandRule % follow table convention X=columns, Y=rows x = colBreakpoints; y = rowBreakpoints; z = v; xName = colName; yName = rowName; else % Update graph. The data is displayed in a way that means the user can % rotate the axes to make the X/Y axis orientation match the table x = rowBreakpoints; y = colBreakpoints; z = v'; locks = locks'; xName = rowName; yName = colName; Selected = Selected(:,[2 1]); end obj.Dragger.setTableData(x, y, z, locks,Selected); set(obj.Axes, 'XLim', mbcmakelimits(x), ... 'XTick',tickCalculation(x),... 'YLim', mbcmakelimits(y), ... 'YTick',tickCalculation(y),... 'ZLim', mbcmakelimits(z, 'loose')); mbcxlabel(obj.Axes, xName); mbcylabel(obj.Axes, yName); function x = tickCalculation(x) x = unique(x); while length(x)>12 if mod(length(x),2) == 1 % odd length x = x(1:2:end); else % include end breakpoint x = [x(1:2:end-1);x(end)]; end end