MATLAB Answers

Selecting points from UI Axes App Designer MATLAB R2019a

137 views (last 30 days)
I am plotting this histogram on UI Axes App Designer R2019a, and I want the user to be able to interactively split the plot using vertical lines (so that I can get the X coordinate at which they are placed). I was previously using getpts, which does not seem to work on UI Axes. Is there a solution for this?

  0 Comments

Sign in to comment.

Accepted Answer

Abhilash Padma
Abhilash Padma on 16 Aug 2019
I understand that you want to split the plot using vertical lines whenever you click on the axes. But, there is no built-in functionality of adding callbacks to UIAxes as of now. Rather, consider using the ButtonDownFcn callback of plot object to draw vertical lines. Here, the plot object can be used to get your expected output.The following code below may help you solve the problem.
p=plot(app.UIAxes,1:10);
p.ButtonDownFcn=@mouseClick;
function mouseClick(~,~)
cp=get(app.UIAxes,'CurrentPoint');
xline(app.UIAxes,cp(1,1));
end

  3 Comments

Manoj Malviya
Manoj Malviya on 17 Jan 2020
I got an error:
Undefined function 'mouseClick' for input arguments of type 'matlab.graphics.chart.primitive.Line'.
Error while evaluating Line ButtonDownFcn.
Please let me know what can be done
Nick Kohout
Nick Kohout on 22 Apr 2020
I got it to work by making mouseClick a separate m file. Also, I had to change the first line to cp=src.Parent.CurrentPoint;

Sign in to comment.

More Answers (0)

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by