Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Add a callback function for impoint object

Asked by JM on 1 Aug 2012

I have a GUI where the user uses impoint to add points to the axes. Whenever an impoint object is created, I want to add a callback function that is called whenever the point is dragged. I also want several inputs to be passed to the callback function. How do I do this?

I think this uses iptaddcallback(h,callback,func_handle), but I can't figure out how to pass inputs to the function handle, or what to use for the 'callback' property. New to Matlab here :P Any help would be great, thanks!

0 Comments

JM

Products

No products are associated with this question.

2 Answers

Answer by Sean de Wolski on 1 Aug 2012
Edited by Sean de Wolski on 8 Aug 2012

Sounds like you will want to use its 'addNewPositionCallback' function.

More

I think you can pass it the typical way using a cell array that contains the function handle and additional inputs. E.g:

h = figure;
f = @(src,evt,x) disp(x);
x = 'pi';
iptaddcallback(h, 'WindowButtonMotionFcn', {f,x});

doc for this

4 Comments

Image Analyst on 1 Aug 2012

What additional variables do you need access to?

JM on 7 Aug 2012

I need to pass in the GUI handles structure so that I can make changes to it.

Sean de Wolski on 8 Aug 2012

See More

Sean de Wolski
Answer by Image Analyst on 1 Aug 2012

What is the use case for this? I don't understand why every point has to have its own individual callback? Are you sure you don't just want the user to click several points and then you run some function when they're done clicking on points?

2 Comments

JM on 1 Aug 2012

The GUI has a video in the background. The points are marking moving objects in the video. The user places points on objects, advances to a later frame, and drags the points to wherever the objects have moved to. I want to save all the previous positions of the points in a struct array.

It's fine if all the points call the same callback function... it's not supposed to be complicated...

Image Analyst on 1 Aug 2012

What would you do in the callback? Anyway, can't you just call ginput and then put whatever code it is that you want to run right after ginput returns with the coordinate? That's how I would approach it because it seems a lot easier.

Image Analyst

Contact us