Effacer les filtres
Effacer les filtres

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

24 vues (au cours des 30 derniers jours)
Marina Llopis Segura
Marina Llopis Segura le 23 Mar 2023
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

Réponse acceptée

Kevin Holly
Kevin Holly le 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".

Plus de réponses (0)

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by