필터 지우기
필터 지우기

How to zoom on the mouse pointer

조회 수: 7 (최근 30일)
Luca Tognetti
Luca Tognetti 2023년 1월 11일
편집: Cameron 2023년 1월 11일
Hi, I'm using the app designer and I need to select points from a plot. To increase the accuracy of the selected points I would like that after clicking a button in the app it activates a zoomed view of the pointer in a UIAxes next to the plot (where there is the "PREVIEW" label).
How can I achieve this function? Thanks, Luca.

채택된 답변

Cameron
Cameron 2023년 1월 11일
편집: Cameron 2023년 1월 11일
I'll post how I was able to do what you're asking. For your application, there may be a slight difference because you are using a picture rather than a plot in your big UIAxes, but this should get you 95% of the way there.
% Window button motion function: UIFigure
function UIFigureWindowButtonMotion(app, event)
PointerLocation = get(app.UIFigure,'CurrentPoint'); %location of pointer
axisYcoords = [app.UIAxes.InnerPosition(2),...
app.UIAxes.InnerPosition(2) + app.UIAxes.InnerPosition(4)]; %UIAxes y coordinates
axisXcoords = [app.UIAxes.InnerPosition(1),...
app.UIAxes.InnerPosition(1) + app.UIAxes.InnerPosition(3)]; %UIAxes x coordinates
%if statement basically asking if you're pointing inside the UIAxes
%InnerPosition and also asks if there is data in the UIAxes. You're
%using a picture so that may need to be updated for you
if PointerLocation(1) > axisXcoords(1) &&...
PointerLocation(1) < axisXcoords(2) &&...
PointerLocation(2) > axisYcoords(1) &&...
PointerLocation(2) < axisYcoords(2) &&...
~isempty(app.UIAxes.Children)
ZoomMag = 10; %zoom magnification
xCalibrate = (app.UIAxes.XLim(2) - app.UIAxes.XLim(1))/...
app.UIAxes.InnerPosition(3); %x value per UIAxes inner pixel
yCalibrate = (app.UIAxes.YLim(2) - app.UIAxes.YLim(1))/...
app.UIAxes.InnerPosition(4); %y value per UIAxes inner pixel
%find what your x and y value are at your cursor within the UIAxes
xValue = xCalibrate*(PointerLocation(1)-app.UIAxes.InnerPosition(1));
yValue = yCalibrate*(PointerLocation(2)-app.UIAxes.InnerPosition(2));
%need to get original data
xData = app.UIAxes.Children.XData;
yData = app.UIAxes.Children.YData;
%plot the pointer location as a black x and plot the original data
%on UIAxes2
plot(app.UIAxes2,...
xValue,yValue,'xk',...
xData,yData,'-o')
%adjust the x and y limits on UIAxes2
xlim(app.UIAxes2,...
[xValue - (app.UIAxes.XLim(2) - app.UIAxes.XLim(1))/ZoomMag,...
xValue + (app.UIAxes.XLim(2) - app.UIAxes.XLim(1))/ZoomMag])
ylim(app.UIAxes2,...
[yValue - (app.UIAxes.YLim(2) - app.UIAxes.YLim(1))/ZoomMag,...
yValue + (app.UIAxes.YLim(2) - app.UIAxes.YLim(1))/ZoomMag])
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by