필터 지우기
필터 지우기

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

조회 수: 24 (최근 30일)
Marina Llopis Segura
Marina Llopis Segura 2023년 3월 23일
답변: Kevin Holly 2023년 3월 24일
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

채택된 답변

Kevin Holly
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개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by