code to select a jpg image from a folder in matlab
49 views (last 30 days)
More Answers (1)
Image Analyst on 17 Mar 2017
% 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;
% Get the name of the file that the user wants to use.
defaultFileName = fullfile(startingFolder, '*.jpg');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
% User clicked the Cancel button.
fullFileName = fullfile(folder, baseFileName)
theImage = imread(fullFileName);
But much more user friendly is to use a listbox where your users can simply click on the image they want. Why force them to deal with a tedious and cruel file-browse dialog box every time? Why be mean to your users? Make it EASY for them instead. See MAGIC: http://www.mathworks.com/matlabcentral/fileexchange/24224-magic-matlab-generic-imaging-component