Use addNewPositionCallback to updates stored line coordinates in GUIDE

1 次查看(过去 30 天)
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!

采纳的回答

Greg
Greg 2018-2-21
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 个评论
Farbos de Luzan
Farbos de Luzan 2018-2-21
编辑:Farbos de Luzan 2018-2-21
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:

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by