get 3D coordinate (x,y,z) of a surf plot on mouse click in App Designer

I created a surf plot in App Designer, and when I mouse click on the figure, it can display the (x,y,z) coordinate on the plot, However, I could not find a way to directly access and save x, y, z coordinate of the mouse click to variables to allow further data processing. Can someone help me with that? thank you very much.
Following is a code how I initialize my surf plot, I used UIAxe for holding my surf plot:
% initialize figure 1
app.UIAxes_X = 10:1:50;
app.UIAxes_Y = 1:0.1:3;
app.UIAxes_Z = NaN(size(app.UIAxes_Y,2),size(app.UIAxes_X,2));
app.surf_handle = surf(app.UIAxes, app.UIAxes_X, app.UIAxes_Y,app.UIAxes_Z);

4 Commenti

add this to your intialization
app.surf_handle.ButtonDownFcn = @app.yourcoordinatehandlerfunction
create a function in your app with name yourcoordinatehandlerfunction.
function yourcoordinatehandlerfunction(app,surf_handle,event)
click_coords = event.IntersectionPoint;
end
thank you Mohammad Sami ! Your solution works!
Just one minor question: now that I used your code, the 'dot' shown on the surf plot upon mouse-click doesn't appear anymore. This is not really important feature-wise, but it helps to give feedback to the user.
Do you know how to enable to show the 'dot'?
You are probably referring to the data tip. What is the version of matlab you are using ?
it's probably data tip.
I'm using version 2019b.

Accedi per commentare.

Risposte (0)

Richiesto:

il 8 Gen 2020

Commentato:

il 9 Gen 2020

Community Treasure Hunt

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

Start Hunting!

Translated by