How to zoom on the mouse pointer
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Luca Tognetti
am 11 Jan. 2023
Bearbeitet: Cameron
am 11 Jan. 2023
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.
0 Kommentare
Akzeptierte Antwort
Cameron
am 11 Jan. 2023
Bearbeitet: Cameron
am 11 Jan. 2023
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!