MATLAB: How to pass Buttondwn function output parameter

buttondownfcnguide

Dear All,
How can I pass an output parameter for buttondownfcn?
set(handles.b,'ButtonDownFcn', {@displayMontage, handles});
function curwell = displayMontage(src, evt, handles)
curwell = get(gco,'position');
handles = updateVisCircleColor(curwell(1), curwell(2), 'red', handles);
I want to pass "curwell" back to the initial function call. How can this be done?
Thanks,
Mathew

Best Answer

If by "initial function call" you mean the call
set(handles.b,'ButtonDownFcn', {@displayMontage, handles});
that configured the callback, then the answer is that you cannot do that: that function is probably no longer running, and MATLAB does not keep track of which function or which line of code configured a particular property.
However, you could do something like,
set(handles.b, 'ButtonDownFcn', {@displayMontage, handles}, 'UserData', []);
waitfor(handles.b, 'UserData')
curwell = get(handles.b, 'UserData');
function displayMontage(src, evt, handles)
curwell = get(gco,'position');
handles = updateVisCircleColor(curwell(1), curwell(2), 'red', handles);
set(src, 'UserData', curwell);