Я не 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
Вы предполагаете, что отображаемая информация будет следовать за мышью при ее перемещении? Или в фиксированном месте где-то в графическом интерфейсе или в центре каждого сегмента? – Will
Оба будут в порядке. Информация должна просто зависеть от положения (x, y) изображения, которое мышь в настоящее время витает выше. – mcExchange