MATLAB Answers

1

How can I use ginput in app designer?

Asked by Jaime Serrano on 4 Apr 2018
Latest activity Answered by Richard Saumarez on 18 Jun 2019
I would like to select a range of points from one particular UIAxes in my app.
I have tried to use ginput ([x,y=ginput]), but the applications prompts an additional empty plot to select the range of points. How can I point an specific UIAxes?
Kind Regards

  0 Comments

Sign in to comment.

Tags

5 Answers

Answer by Birdman
on 4 Apr 2018
 Accepted Answer

You can't. If you check the documentation of ginput, you will see it can not take a predefined axes as an input argument:
There might be custom written functions for that though, you just have to google it.

  0 Comments

Sign in to comment.


Answer by HM
on 31 Aug 2018

I found this thread because I was looking for the same thing. We definitely need a 'ginput' function that works within a UIFigure.
However, I did find a workaround: invoke a new 'normal' matlab figure with 'figure' (e.g. MyFigure = figure;) plot on that figure any plots/graphics that you have plotted on your UIFigure (any relevant graphics that you need on there to be able to click relative to). Note, use the traditional plot() command, rather than the plot(app.UIFigure, ) command. Then use the ginput function with that figure. (e.g. MyPoints = ginput;) then delete the figure, and use the recorded values as desired. (e.g. delete(MyFigure); )
This actually worked well for me, as the 'pop-up' figure is larger than my UIFigure, allowing for more accurate mouse clicking.
Hope that helps. Cheers, Hugh.

  0 Comments

Sign in to comment.


Answer by Jon Nykiel on 18 Jun 2019

Unfortunately, ginput is not supported within appdesigner. However, as of R2019A, the CurrentPoint property can be used within a WindowButtonDown function to get the coordinates of a button click within UIAxes.
Simple example:
function UIFigureWindowButtonDown(app, event)
temp = app.UIAxes.CurrentPoint; % Returns 2x3 array of points
loc = [temp(1,1) temp(1,2)]; % Gets the (x,y) coordinates
end

  0 Comments

Sign in to comment.


Answer by chrisw23 on 18 Jan 2019
Edited by chrisw23 on 18 Jan 2019

You can define a ButtonDownFcn callback that delivers 'Hit' event data for axes, which has an IntersectionPoint property. This is also valid for lines, but not for ie. the MainFigure (MouseData event only).
This works fine although the AppDesigner doesn't support callback properties for Axes ( tested with SubPlot with Panel Parent in R2018b ).
app.myAx = subplot(2,1,1,'Parent',app.Panel); % create plot
app.myAx.ButtonDownFcn = createCallbackFcn(app, @app.getMousePosition, true);
function getMousePosition(app,source,event)
switch event.EventName
case 'Hit'
% Properties: Btn/IntersectionPoint/Src/Evnt
posData = event.IntersectionPoint; % to be used for calc
case 'MouseData'
% Properties: Src/EvntName
end
end
Hope it helps
Christian

  2 Comments

Is there any solution for app designer also to get points from multiple line plot.
I want draw a staright child line on parent line by clicking on it.
Brilliant!
I've been tearing my hair out trying to solve this.
App designer really need a simple to use mouse position function that isn't as tortuous as this.

Sign in to comment.


Answer by Richard Saumarez on 18 Jun 2019

I agree about the comments on appDesigner
After a lot of work, and bending one's foot round one's ear, one can write a GUI that has most of the functionality written in Visual stdio or Fortran. But it seems counterintuitive and everything that one would like to do, and would think is being easy, is "not supported".
There is no doubt in my mind that appDesigner needs more functionality if one is going to write an artistic, commercially useful, GUI that is not simply knobs and sliders. Apart from the difficulty in getting the mouse position, one desperately needs to be able to draw on the uppermost layer of the GUI, not in a plot, but in the container itself.
I may be being unfair, and this may be possible, but finding one's way around Matlab documentation, apart from the most basic aspects, is really difficult.

  0 Comments

Sign in to comment.