MATLAB Answers

get the location of points in a plot by mouse interaction in app designer

2 views (last 30 days)
Roberto
Roberto on 10 Dec 2019
Edited: Adam Danz on 17 Dec 2019
I want to get the coordinate of each point in a plot made in app designer. When I click on the plot, a small box shows up and shows the X, Y and Z values of the point. Is there anyway that I can assign these values to a variable in app designer. I know many people asked this question before and I am aware of displaying graphic limitations of app designer; however, I have the hope that someone suggests a creative solution for this problem.

  1 Comment

Roberto
Roberto on 10 Dec 2019
I found this answer to be very useful. The only missing part is how we can show the values of "coordinateSelected" in the interface. for instance:
app.Label.Text=[num2str(coordinateSelected(1,1)),num2str(coordinateSelected(1,1))]

Sign in to comment.

Answers (1)

Adam Danz
Adam Danz on 10 Dec 2019
Edited: Adam Danz on 17 Dec 2019
That call back function in that answer uses fprintf() to display the results in the command window. To display the results as text in a textbox, simply replace fprintf() with sprintf().
txt = sprintf('[x,y,z] = [%.5f, %.5f, %.5f]', coordinateSelected);
app.Label.Text = txt; % assign char array to text box
If you only want the values
txt = sprintf('%.5f, %.5f, %.5f', coordinateSelected);
app.Label.Text = txt; % assign char array to text box
Both of these examples use 5 decimals of precision which you can adjust as needed.

  0 Comments

Sign in to comment.

Sign in to answer this question.