MATLAB: I want to get the image I got in a function in another function

image processingMATLAB

this is the function I used to get the image
function selectImage_Callback(hObject, eventdata, handles)
[filename, pathname] = uigetfile({'*.jpg';'*.bmp';'*.png''*.jpeg'},'File Selector');
handles.myImage = strcat(pathname, filename);
axes(handles.imageAxes2);
imshow(handles.myImage)
% save the updated handles object
clear axes scale
axis off
guidata(hObject,handles);
and I'm trying to use the same image in another function
function classifyImage_Callback(hObject, eventdata, handles)
net = alexnet;
image = handles.myImage;
image = imresize(image,[227 227]);
label = classify(net,image);
set(handles.imageType, 'String' , label)
%

Best Answer

Try using the user data to save/load variables in different functions:
function selectImage_Callback(hObject, eventdata, handles)
[filename, pathname] = uigetfile({'*.jpg';'*.bmp';'*.png''*.jpeg'},'File Selector');
fullFileName = fullfile(pathname, filename);
handles.myImage = imread(fullFileName); % attending to the 2nd answer of post
axes(handles.imageAxes2);
imshow(handles.myImage)
% Save in user data
img = handles.myImage;
data_image= struct('img',img);
hObject.UserData = data_image;
% save the updated handles object
clear axes scale
axis off
guidata(hObject,handles);
Then in the second function, you load the user data of the first function
function classifyImage_Callback(hObject, eventdata, handles)
% Load the user data of the 1st function
h = findobj('Tag','selectImage');
data_image = h.UserData;
net = alexnet;
image = data_image.img;
image = imresize(image,[227 227]);
label = classify(net,image);
set(handles.imageType, 'String' , label)
In the second function in the findobj you should put the tag of your gui component, I wrote selectImage as it seems this is it.