Peter - perhaps consider not using a while loop. The purpose of the loop seems only to update your two arrays of x and y coordinates for the mouse button down events. If this is the case, why not "record" these positions as soon as you press the mouse button? In the _OpeningFcn of your GUI, initialize two arrays for these coordinates as
function AxesMouseClickExampleGui_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
handles.axesClickX = [];
handles.axesClickY = [];
guidata(hObject, handles);
In your checkbox callback, just clear out these arrays when the checkbox has been selected
function checkbox1_Callback(hObject, eventdata, handles)
if get(hObject,'Value') == 1
set(hObject,'String','Stop Recording');
handles.axesClickX = [];
handles.axesClickY = [];
guidata(hObject,handles);
else
handles.axesClickX
handles.axesClickY
set(hObject,'String','Start Recording');
end
So if the user checks the checkbox, we change the text to "Stop Recording" and empty the arrays. If the user deselects the checkbox, then we change the text to "Start Recording" and write out the two arrays of coordinates.
In the button down callback (for your axes) we capture the current point and record it only if the user has checked the checkbox
function axes1_ButtonDownFcn(hObject, eventdata, handles)
if get(handles.checkbox1,'Value') == 1
currentPos = get(hObject,'CurrentPoint');
handles.axesClickX = [handles.axesClickX ; currentPos(1,1)];
handles.axesClickY = [handles.axesClickY ; currentPos(1,2)];
guidata(hObject,handles);
end
See the attached for an example.
Best Answer