www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@mvgraph2d/imagecb.m

    function imagecb(gr)
%IMAGECB Callback function for graph2d object
%  IMAGECB is called when the graph2d image is clicked on. It displays an
%  axis with info on the point clicked

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



% ask for a new set of yellow axes in right place
[ax,txt]=infoaxes(gr);

ud = gr.DataPointer.info;
data = ud.data;

% Generate the text string.
factors=ud.factors;
if ~isempty(factors)
    if iscell(factors{1,1})
        xfactor=factors{:,1};
    elseif length(factors)>1 && iscell(factors{2})
        xfactor=factors{:,1};
    else
        xfactor=factors(:,1);
    end
else
    xfactor={};
end
if size(factors,2)>1
    if iscell(factors{1,2})
        yfactor=factors{:,2};
    else
        yfactor={};
    end
else
    yfactor={};
end

pnt=get(gr.axes,'CurrentPoint');
xval=round(pnt(1,1));
yval=round(pnt(1,2));

if length(xfactor)<xval
    xfactor=['col ' sprintf('%d', xval)];
else
    xfactor=xfactor{xval};
end

if length(yfactor)<yval
    yfactor=['row ' sprintf('%d', yval)];
else
    yfactor=yfactor{yval};
end
str=['(' xfactor ', ' yfactor '):' sprintf('\n')];
str=[str 'Value=' num2str(data(yval,xval))];
set(txt,'String',str);
% check box is right size
ex=get(txt,'Extent');
pos=get(ax,'Position');
if ex(3)>1
    % stretch in xdir
    pos(3)=pos(3)*(ex(3)+.1);
end
if ex(4)>1
    % stretch in ydir
    pos(4)=pos(4)*(ex(4)+.1);
end
% check object is within gr boundary
gr_pos = ud.position;
if (pos(1)+pos(3))>(gr_pos(3));
    pos(1)=pos(1)-(pos(1)+pos(3)-gr_pos(3)+1);
end

set(ax,'Position',pos,'Visible','on');

bm = xregGui.ButtonUpManager(ancestor(gr.axes,'figure'));
bm.getNextEvent({@i_destroy,ax});


function i_destroy(src,evt,ax)
delete(ax)