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

works great thanks !!!
sorry - checked it in my environment - ran your script and got:
"Functionality not supported with figures created with the uifigure function. For more information, see Graphics Support in App Designer."
what am i doing wrong?
thanks again!
mat
Adam Danz
Adam Danz 2021년 1월 18일
편집: Adam Danz 2021년 1월 18일
It works in 2020b. I see you're using 19a so you'll need to update. The feature wasn't supported in your release.
thanks again!..
so, there is no way to circumvent this in 2019a in App Designer?
Adam Danz
Adam Danz 2021년 1월 19일
편집: Adam Danz 2021년 1월 19일
Well, you could replace the uiaxes with regular axes which support the ButtonDownFcn in 19a.
as a last resort.. :)
thanks a lot for all your prompt replies and suggestions !!

댓글을 달려면 로그인하십시오.

 채택된 답변

Adam Danz
Adam Danz 2021년 1월 17일
편집: Adam Danz 2021년 1월 18일

1 개 추천

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품

릴리스

R2019a

질문:

2021년 1월 17일

댓글:

2021년 1월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by