MATLAB: How do i transfer matrix variable of an image from gui callback function to a another call back function (pushbutton1_Callback —-> pushbutton2_Callback)

callbackguitransfervariable

function pushbutton1_Callback(hObject, eventdata, handles)
handles.imgin = uigetfile();
guidata(hObject,handles)
i need to transfer loaded image matrix variable to below function
function pushbutton2_Callback(hObject, eventdata, handles)
imgin = guidata(hObject,handles.imgin);
but i fail to get the loaded image matrix from here

Best Answer

Tishan - you don't need to use guidata to access the field of handles that has been update with imgin. Rather than doing
function pushbutton2_Callback(hObject, eventdata, handles)
imgin = guidata(hObject,handles.imgin);
just do
function pushbutton2_Callback(hObject, eventdata, handles)
if isfield(handles,'imgin')
imgin = handles.imgin;
% rest of code goes here
end
Try the above and see what happens!