Plot a point in a GUI with mouse click
조회 수: 10 (최근 30일)
이전 댓글 표시
I would like to draw a point in the UIAxes. To do this, I want to determine the position of the mouse pointer in the callback function and draw a point with it. I have created this class:
classdef PlottingClass < handle
properties
fig;
ax;
points = [];
end
methods
function self = PlottingClass();
self.fig = uifigure("Name","test");
self.ax = uiaxes(self.fig);
grid(self.ax,"on")
xlabel(self.ax,"Time")
ylabel(self.ax,"Value")
self.ax.ButtonDownFcn = @self.plottingfcn;
end
end
methods
function plottingfcn(self,axes,hit)
allPoint = hit.IntersectionPoint;
x= allPoint(1);
y= allPoint(2);
z= allPoint(3);
plot(axes,x,y,"o",MarkerSize=2)
self.points = [self.points , [x;y]]
grid(axes,"on")
xlabel(axes,"Zeit")
ylabel(axes,"Value")
disp("x "+x)
disp("y "+y)
disp("z "+z)
end
end
end
When I create an object and click in the UIAxes, I get this output:
x -0.12607
y 1.2151
z -1
Now I wanted to ask why z = -1.
I hope you can help me.
Thank you very much.
댓글 수: 0
채택된 답변
Voss
2024년 2월 27일
편집: Voss
2024년 2월 27일
Apparently plot changes the axes' ZLim to [-1 1], which you can check by displaying the ZLim before and after the first click.
You can avoid that by setting the ZLimMode to 'manual' (or just setting ZLim to [0 1] or whatever) initially.
(And while you're doing that, you might also want to set the XLim/XLimMode and YLim/YLimMode in order to avoid having those limits automatically update when plot is called, because after XLim/YLim auto-updating, the plotted point may no longer be at the mouse pointer location.)
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Vector Fields에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!