MATLAB Answers

1

How can I use ginput in app designer?

Asked by Jaime Serrano on 4 Apr 2018
Latest activity Edited by chrisw23
on 18 Jan 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

3 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 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

  0 Comments

Sign in to comment.