make the XTickLabel mouse sensitive in UIAxes

1 Ansicht (letzte 30 Tage)
Shlomi Bejerano
Shlomi Bejerano am 17 Jan. 2021
Kommentiert: Shlomi Bejerano am 19 Jan. 2021
hi
i would like to make the XTickLabel entries (or Y or Z dimension) mouse sensitive in UIAxes. pressing a mouse left on a label should callback a function.
thanks a lot !!!
mat
  6 Kommentare
Adam Danz
Adam Danz am 19 Jan. 2021
Bearbeitet: Adam Danz am 19 Jan. 2021
Well, you could replace the uiaxes with regular axes which support the ButtonDownFcn in 19a.
Shlomi Bejerano
Shlomi Bejerano am 19 Jan. 2021
as a last resort.. :)
thanks a lot for all your prompt replies and suggestions !!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Adam Danz
Adam Danz am 17 Jan. 2021
Bearbeitet: Adam Danz am 18 Jan. 2021
This demo uses a ButtonDownFcn function on the axes to detect when the left mouse button selects an x-tick label. The selection updates the axis title. Requires Matlab r2020b or later.
% Create demo UI Figure
fig = uifigure();
ax = uiaxes(fig);
ax.ButtonDownFcn = @axisButtonDownFcn;
function axisButtonDownFcn(ax, event)
% Responds to mouse click on axes. If click is above the lower y-axis
% there is no action. If the click is on or around the x-axis ticks,
% the nearest tick is located. Only accepts left mouse clicks.
% Only accept left mouse clicks
if event.Button ~= 1
return
end
% Only accepts clicks lower than min(ylim)
if event.IntersectionPoint(2) > min(ax.YLim)
return
end
% Get closest x-tick to the click
[~, tickIdx] = min(abs(ax.XTick - event.IntersectionPoint(1)));
tickSelected = ax.XTick(tickIdx);
% Update axis title to indicat tick selected
ax.Title.String = sprintf('x=%.4g selected', tickSelected);
end

Weitere Antworten (0)

Kategorien

Mehr zu Develop uifigure-Based Apps finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by