app designer: save a point on a graph when you click on it

27 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Kevin Holly
Kevin Holly il 24 Mar 2023
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".

Più risposte (0)

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by