Use addNewPositionCallback to updates stored line coordinates in GUIDE

1 view (last 30 days)
Hello all,
I have read everything I could about the use of Callbacks in GUIDE, but I may use a little help from experienced users. I am trying to update a handles every time I resize an imline line, so I can use their coordinates later in my program. I cannot find the correct way to word it in Matlab. Here is an extract of the code:
handles.h = imline(gca,[-1 -1],[-2 2]);
id = addNewPositionCallback(handles.h,@hpos);
% Update handles structure
guidata(hObject, handles);
function hpos(h,handles)
% Display image info
set(handles.iminfo, 'String',{['It works!']});
I get the following error message: "Error while evaluating Figure WindowButtonMotionFcn.
Not enough input arguments."
Anybody could guide me in the right direction? Thanks in advance!

Accepted Answer

Greg
Greg on 21 Feb 2018
From the documentation:
addNewPositionCallback — Add new-position callback to ROI object
id = addNewPositionCallback(h,fcn) adds the function handle fcn to the list of new-position callback functions of the ROI object h. Whenever the ROI object changes its position each function in the list is called with the syntax:
fcn(pos)
where pos is of the form returned by the object's getPosition method.
The return value, id, is used only with removeNewPositionCallback.
This indicates that only 1 input is being passed to hpos, and you've define it to require 2 inputs. I'm not sure it'll work, but I would try:
handles.h = imline(gca,[-1 -1],[-2 2]);
id = addNewPositionCallback(handles.h,{@hpos,handles.iminfo});
% Update handles structure
guidata(hObject, handles);
function hpos(pos,iminfo_obj)
% Display image info
set(iminfo_obj, 'String','It works!');
% I'm assuming 'It works!' is a placeholder and you want to use pos above
  2 Comments
Farbos de Luzan
Farbos de Luzan on 21 Feb 2018
Edited: Farbos de Luzan on 21 Feb 2018
Thank you very much Greg for this quick answer. Indeed the "It Works!" was supposed to be a placeholder (I wanted to keep it simple for a start). Your post actually helped me understanding how to specify the inputs to my callback function. Then I had another error message that I could fix thanks to this post:

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!