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.

采纳的回答

Voss
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 个)

类别

Help CenterFile Exchange 中查找有关 Vector Fields 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by