MATLAB: Imread help in reading a image form the path in a handles variable

digital image processingimageimage processingimread

I am using this code under a push button to browse and save the path for a image under handles.myimage for further use in another push button.
if true
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

[filename pathname] = uigetfile({'*.jpg';'*.bmp'},'File Selector');
handles.myImage = strcat(pathname, filename);
%axes(handles.axes1);
imshow(handles.myImage)
set(handles.edit1,'string',handles.myImage);
% save the updated handles object
guidata(hObject,handles);
end
So now the complete path of the image is in handles.myImage. i want to use this path as the input of 'imread' function for this code block
if true
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton9 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clear all
clc
FDetect = vision.CascadeObjectDetector;
O = get(handles.edit1,'string');
I = imread('C:\Users\Abhijeet\Desktop\PROJECT\Code\Images\img4.jpg');
BB = step(FDetect,I);
figure,
imshow(I); hold on
for i = 1:size(BB,1)
rectangle('Position',BB(i,:),'LineWidth',5,'LineStyle','-','EdgeColor','r');
Please help me out. Any links to the required answer or suggestion are appreciated. Thanks in advance !

Best Answer

It is a really bad idea to clear everything on top of a function by clear all. Simply omit this command. Then there are two ways:
function pushbutton9_Callback(hObject, eventdata, handles)
handles = guidata(hObejct); % Obtain current value
ImageName1 = get(handles.edit1,'string');
ImageName2 = handles.myImage; % Both are the same
I'm still not sure if obtaining the current value of the handles struct is required or if GUIDE cares for updating the value in the input arguments already.