URGENT! Question about using matlab to find the range of frames

1 view (last 30 days)
file_path=input('Enter the file path: ');
obj = mmreader(file_path);
obj
disp('Use image(read(obj,frame number) to find a frame for calibration and to indicate the range of frames for trajectory.')
I put this m file and a avi file in the same folder, when I run the m file it shows: Enter the file path: what should I input then?

Answers (2)

Image Analyst
Image Analyst on 3 Oct 2014
Don't be cruel to your users. I would absolutely hate a programmer who made me type in the full path of a video file. Have them browse for the image and avoid the path problem:
% Have user browse for a file, from a specified "starting folder."
% For convenience in browsing, set a starting folder from which to browse.
startingFolder = 'C:\Program Files\MATLAB';
if ~exist(startingFolder, 'dir')
% If that folder doesn't exist, just start in the current folder.
startingFolder = pwd;
end
% Get the name of the file that the user wants to use.
defaultFileName = fullfile(startingFolder, '*.*');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
  1 Comment
John D'Errico
John D'Errico on 3 Oct 2014
Excellent response - "Don't be cruel to your users."
Always put yourself in the shoes of the person using your code, even if that person is you. Would you really want to be forced to type in some mess of a file path every time this code is used? If not, then don't do it to others. Use uigetfile, it is included in MATLAB. And there is uigetdir from the FEX.

Sign in to comment.


Star Strider
Star Strider on 3 Oct 2014
Enter the file path. (It may want the full file path, including the file name.) It will not generate an error if the m-file and the .avi file are in the same directory.

Community Treasure Hunt

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

Start Hunting!