MATLAB: Select one of two images displayed on a GUI

guiimage processingmatlab gui

Hey guys, im experiencing some problems. I have a GUI where I display my two images so the user can easily choose one of them through two buttons.
function removedBackgroundSelectorView_OpeningFcn(hObject, eventdata, handles, varargin)
axes(handles.axes1);
imshow(varargin{1}{1});
axes(handles.axes2);
imshow(varargin{1}{2});
handles.output = hObject;
guidata(hObject, handles);
The callbacks:
function button1_Callback(hObject, eventdata, handles)
handles.output = handles.axes1;
uiresume;
function button2_Callback(hObject, eventdata, handles)
handles.output = handles.axes2;
uiresume;
And the output function
function varargout = removedBackgroundSelectorView_OutputFcn(hObject, eventdata, handles)
uiwait;
varargout{1} = getimage(handles.output);
So, there is my problem, it does not matter wich button I press, I always get the image from axes2. I tried really hard to solve it by myself but had no results.
Thanks

Best Answer

You need to call guidata() otherwise handles is not updated permanently. You made a new output field but it's basically thrown away when you exit the push button callback.
Related Question