app designer: save a point on a graph when you click on it
13 ビュー (過去 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!