Hi. Im trying to use the handy draggable function https://www.mathworks.com/matlabcentral/fileexchange/4179-draggable for a GUI im working on. I want to drag a line and have the x coordinate update in a textbox after the user releases the mouse. Im having some issues implementing it due to some issue with handles that i cant figure out.
This is how I added the draggable line:
axes(handles.axis1)plot(y)hold onq_line = line([x1 x1],[y2 y1], 'color', 'k','linewidth',0.5, 'linestyle', '--'); draggable(qon_line,'h',[x1-50 x2+50],'endfcn',@update_drag_line_values);
then i have a separate function:
function new_line_xcoord = update_drag_line_values(line)drag_line_xdata = round(get(line,'XData'));new_line_xcoord = drag_line_xdata(1)
but when I try to do anything involving handles I get either this error:
Undefined variable "handles" or class "handles.variable1".Error in GUI_name>update_drag_line_values (line 4381)handles.variable1Error in draggable>deactivate_movefcn (line 311) feval(user_endfcn,h); % added by SMB, modified by FB
Error while evaluating Figure WindowButtonUpFcn.
or this error:
Undefined function or variable 'hObject'.Error in GUI_name>update_drag_line_values (line 4378)handles = guidata(hObject); % load handles variables
Error in draggable>deactivate_movefcn (line 311) feval(user_endfcn,h); % added by SMB, modified by FBError while evaluating Figure WindowButtonUpFcn.
Ive tried to pass handles into the endfcn in various ways including:
axes(handles.axis1)plot(y)hold onq_line = line([x1 x1],[y2 y1], 'color', 'k','linewidth',0.5, 'linestyle', '--'); draggable(qon_line,'h',[x1-50 x2+50],'endfcn',{@update_drag_line_values,handles});
but nothing seems to work….any help would be appreciated. thanks!!
Best Answer