How to extract file path from BROWSE button using uigetfile to be used in another push button in MATLAB GUI?

1 view (last 30 days)
I am creating a GUI using MATLAB's guide. I created a BROWSE button which asks the user to select a video file for analysis using the uigetfile function. The video file is then set to play in an axes within the GUI.
Now, I have another push button that shall be pressed to process the selected video. This process however requires the file path of the video file.
How can I extract the file path from the other previous button (BROWSE) so I may use it for the next push button (CARCOUNT)? THANK YOU!
HERE IS A SECTION OF MY CODE:
function browse_Callback(hObject, eventdata, handles)
% hObject handle to browse (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileName,FilePath]=uigetfile('*.avi', 'Select a video');
ExPath = [FilePath FileName]
set(handles.file_path,'String',ExPath);
guidata(hObject, handles);
vid = VideoReader(ExPath);
vidFrames = read(vid); %read in all video frames
numFrames = get(vid, 'numberOfFrames'); %get the number of frames from the video file
%Create a movie structure from the video frames initialized.
for k = 1 : numFrames
mov(k).cdata = vidFrames(:,:,:,k);
mov(k).colormap = [];
end
%Create a figure
hf = handles.vid_play_box;
% Resize figure based on the video's width and height
set(hf);
% Playback movie once at the video's frame rate
movie(hf, mov, 1);
function initializeprocess_Callback(hObject, eventdata, handles)
% hObject handle to carcount (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
filename = browse_Callback('ExPath');

Accepted Answer

Walter Roberson
Walter Roberson on 13 Jun 2017
You used
set(handles.file_path,'String',ExPath);
so in the routine that needs the name, you can use
get(handles.file_path, 'String')
By the way, please learn to use fullfile(). You currently use
ExPath = [FilePath FileName]
but it is undefined as to whether the director ('FilePath') returned by uigetfile ends in a directory delimiter or not, and there are no promises made that it would be consistent from call to call.

More Answers (0)

Categories

Find more on Printing and Saving in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!