Usage of uigetfile in matlab
Function: uigetfile
[Function description] creates a standard dialog box and obtains the file name through interactive operations.
[Function usage]
Uigetfile: displays a modal dialog box that lists the files and directories in the current directory. You can select a file name to be opened. If the file name is valid and the file exists, the uigetfile function returns the file name when you click Open. If it does not exist, uigetfile displays an error message indicating the value of the control return dialog box. You can enter another file name or click the Cancel button. If you click the Cancel button or close the dialog box, the uigetfile function returns 0.
[FileName, PathName, FilterIndex] = uigetfile (FilterSpec): Create and display a dialog box to list files in the current directory.
FilterSpec determines the initial display of a file. It can be the full name of a file or contain wildcards *. For example, '*. doc' indicates listing all file files.
If FilterSpec is a string containing a file name, the file name domain where the file name is located will be selected and displayed, and the extension name of the file will be used as a filter;
If FilterSpec is a string containing the file path, for example '. ','.. 'or'/', such '.. /*. m' indicates listing all m files in the current directory;
If FilterSpec is a cell array, the first column is the extension list, and the second column is the description list;
If FilterSpec does not specify a path object, uigetfile uses all file types in the default path.
Usage of this function:
[FileName, PathName, FilterIndex] = uigetfile (FilterSpec, DialogTitle, DefaultName)
FileName: returned file name
PathName: The Path Name of the returned file.
FilterIndex: The selected file type.
FilterSpec: file type settings
DialogTitle: the title of the open dialog box
DefaultName: the default object name.
Example:
(1) simplest example
[FileName,PathName] = uigetfile('.m','Select the M-file');
(2) set multiple file types
>> [filename, pathname] = ... uigetfile({'*.m';'*.mdl';'*.mat';'*.*'},'File Selector');
(3) set description for the file type, pay attention to the writing format
>> [filename, pathname] = uigetfile( ...{'*.m;*.fig;*.mat;*.mdl','MATLAB Files (*.m,*.fig,*.mat,*.mdl)'; '*.m', 'M-files (*.m)'; ... '*.fig','Figures (*.fig)'; ... '*.mat','MAT-files (*.mat)'; ... '*.mdl','Models (*.mdl)'; ... '*.*', 'All Files (*.*)'}, ... 'Pick a file');
(4) You can return the sequence number of the selected file type and set multiple file selections. Note that when only one file is selected, the returned filename is a string, when multiple files are selected, the returned cellular type is displayed.
>> [filename, pathname, filterindex] = uigetfile( ...{ '*.mat','MAT-files (*.mat)'; ... '*.mdl','Models (*.mdl)'; ... '*.*', 'All Files (*.*)'}, ... 'Pick a file', ... 'MultiSelect', 'on');
(5) You can set the default file name.
>> uigetfile({'*.jpg;*.tif;*.png;*.gif','All Image Files';... '*.*','All Files' },'mytitle',... 'myfile.jpg')
TIPS: When a file is returned, you can use fullfile to combine the path and file name. For example:
>> [filename, pathname] = uigetfile('*.m', 'Pick an M-file');if isequal(filename,0) disp('User selected Cancel')else disp(['User selected', fullfile(pathname, filename)])endUser selected Cancel
Use of uigetfile function in matlab
[FileName, PathName, FilterIndex] = uigetfile ('*. xls'); % get the information of the selected file (file name, path, etc)
If FilterIndex
[A, T] = xlsread ([PathName, FileName]); % read the xls file. For details, see the help of xlsread.
End
Uigetfile
In matlab programming, you may want to call a file on your computer. In this case, use the traditional windows file to open the dialog box and try again:
[Filename, pathname] = uigetfile (...
{'*. Jpg; *. tif; *. png; *. gif', 'all Image Files ';...
'*. *', 'All Files '},...
'Select the image to be modified (multiple options )',...
'Elelect ', 'on ');
This function is used
[FileName, PathName, FilterIndex] = uigetfile (FilterSpec, DialogTitle, DefaultName)
FileName: returned file name
PathName: The Path Name of the returned file.
FilterIndex: The selected file type.
FilterSpec: file type settings
DialogTitle: the title of the open dialog box
DefaultName: the default object name.
Example: (with help from matlab)
1. In the simplest form, only one file type is set.
[FileName, PathName] = uigetfile ('*. M', 'select the m-file ');
2. Set Multiple File Types
[Filename, pathname] =...
Uigetfile ({'*. M';' *. mdl ';' *. M'; '*. *'}, 'file Selector ');
3. You can set instructions for file types. Note the writing format.
[Filename, pathname] = uigetfile (...
{'*. M ;*. fig ;*. mat ;*. mdl', 'matlab Files (*. m ,*. fig ,*. mat ,*. mdl )';
'*. M','m-files (*. m )';...
'*. Fig', 'figures (*. fig )';...
'*. Mat', 'Mat-files (*. MAT )';...
'*. Mdl', 'models (*. mdl )';...
'*. *', 'All Files (*.*)'},...
'Pick a file ');
4. you can return the sequence number of the selected file type and set multiple file selections. Note that when only one file is selected, the returned filename is a string. When multiple files are selected, the type of the returned metacell.
[Filename, pathname, filterindex] = uigetfile (...
{'*. Mat', 'Mat-files (*. MAT )';...
'*. Mdl', 'models (*. mdl )';...
'*. *', 'All Files (*.*)'},...
'Pick a file ',...
'Multis... the remaining full text>