Use addNewPositionCallback to updates stored line coordinates in GUIDE

1 Ansicht (letzte 30 Tage)
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!

Akzeptierte Antwort

Greg
Greg am 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 Kommentare
Farbos de Luzan
Farbos de Luzan am 21 Feb. 2018
Bearbeitet: Farbos de Luzan am 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:

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by