Plot a point in a GUI with mouse click
2 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Voss
on 27 Feb 2024
Edited: Voss
on 27 Feb 2024
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 Comments
More Answers (0)
See Also
Categories
Find more on Vector Fields in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!