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

조회 수: 1 (최근 30일)
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');

채택된 답변

Walter Roberson
Walter Roberson 2017년 6월 13일
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.
  댓글 수: 1
Harlee Quizzagan
Harlee Quizzagan 2017년 6월 13일
Thank you so much Walter! I did use this and it is indeed what I needed. Thank you so much for the suggestion as well. :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by