MATLAB: Use addNewPositionCallback to updates stored line coordinates in GUIDE

addnewpositioncallbackcallbackguidehandlesimlineMATLABrefreshresize

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!

Best Answer

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