app designer: save a point on a graph when you click on it
27 次查看(过去 30 天)
显示 更早的评论
hello.
I would like to click on a graph in matlab app designer, where the x and y are automatically displayed. Then I want to save the x component.
How can I do it?
thanks
0 个评论
采纳的回答
Kevin Holly
2023-3-24
You could create a listener that tracks the position of your mouse within you axes (app.UIAxes) and then save the x and y coordinates as under the property values x and y, respectively.
properties
x
y
end
Add listener function as a callback to the UIFigure
app.UIFigure.WindowButtonMotionFcn={@mouseMotionCB_sensorplacement ,app};
Listener function:
function mouseMotionCB_sensorplacement(fig,event,app)
eventname = event.EventName;
switch eventname
case 'WindowMouseMotion'
% Obtain Coordinates of mouse for each of the 4 axes
currentPoint1 = app.UIAxes.CurrentPoint(1,1:3);
x1 = currentPoint1(1);
y1 = currentPoint1(2);
% Change pointer to crosshair when within axes.
if (app.UIAxes.XLim(1)<x1)&&(x1<app.UIAxes.XLim(2)) && (app.UIAxes.YLim(1)<y1)&&(y1<app.UIAxes.YLim(2))
set(fig,'Pointer','crosshair');
else
set(fig,'Pointer','arrow'); % When outside of axes, return pointer to arrow
end
case 'WindowMousePress'
% When mouse is pressed, get coordinates
currentPoint1 = ax1.CurrentPoint(1,1:3);
app.x = currentPoint1(1);
app.y = currentPoint1(2);
end
I am not entirely sure what you mean by "where the x and y are automatically displayed".
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!