Plot a point in a GUI with mouse click
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.
Accepted Answer
More Answers (0)
Categories
Find more on Data Exploration 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!