我不是100%明白“几个标签”的含义,但我认为你希望能够在图像上显示弹出式编辑,我认为以下是你想要的:
function hoverTest
% create a figure (units normalized makes updating the position easier in the callback
f = figure ( 'units', 'normalized' );
% create an axes
ax = axes ( 'parent', f );
% load some data for plotting
c = load ( 'clown' );
% plot the data
image ( c.X, 'parent', ax );
% create a uipanel to host the text we will display
uip = uipanel ( 'parent', f, 'position', [0 0 0.18 0.05], 'visible', 'off' );
% create a text control to display the image info
txt = uicontrol ( 'style', 'edit', 'parent', uip, 'units', 'normalized', 'position', [0 0 1 1] );
% assign the callback for when the mouse moves
f.WindowButtonMotionFcn = @(obj,event)updateInfo(f,uip,ax,txt,c.X);
end
function updateInfo ( f, uip, ax, txt,img )
% update the position of the uipanel - based on the current figure point (normalized units)
set ( uip, 'Position', [f.CurrentPoint uip.Position(3:4)] );
% Check to see if the figure is over the axes (if not hide)
if ax.CurrentPoint(1,1) < min(ax.XLim) || ...
ax.CurrentPoint(1,1) > max(ax.XLim) || ...
ax.CurrentPoint(1,2) < min(ax.YLim) || ...
ax.CurrentPoint(1,2) > max(ax.YLim)
uip.Visible = 'off';
else
% show the panel
uip.Visible = 'on';
% get the current point
cp = round(ax.CurrentPoint);
% update the text string of the uicontrol
txt.String = sprintf ( 'img(%i,%i) = %i', cp(1,1), cp(1,2), img(cp(1,2),cp(1,1) ) );
end
end