function in matlab uigetfile Use (Recommended)

Sometimes we need to choose the time to write a GUI using matlab file import, so we must first get the file name and path, which use the uigetfile () function, which can pop-up boxes to select a file, this function use as follows:
File = uigetfile
[File, path] = uigetfile
[File, path, INDX] = uigetfile
___ = uigetfile (filter)
___ = uigetfile (filter, title)
___ = uigetfile (filter, title, defname,)
___ = uigetfile (___, 'MultiSelect', mode )

Description:

  1. file = uigetfile opens a modal dialog box, which lists the files in the current folder. Here the user can select or enter the name of the file. If the file exists and is valid, when the user clicks open, uigetfile will return to the file name. If the user clicks Cancel or window close button (X), uigetfile will return 0.
  2. When the user clicks open, [file, path] = uigetfile will return the name and path of the file. If the user clicks Cancel or window close button (X), uigetfile two output parameters will return 0.
  3. When the user clicks open, [file, path, indx] = uigetfile returns the index filter selected in the dialog box.
  4. ___ = uigetfile (filter) specify a file extension, file filter dialog box is displayed according to the extension. This syntax may be used in combination with any of the above-described output parameter syntax. Typically, only the file name matches the file extension.
  5. ___ = uigetfile (filter, title) specify the dialog title. To use the default file filter to filter, but specify a custom header, use empty quotation marks as a filter value. For example:
    File = uigetfile ( '', 'the Select A File')
  6. ___ = uigetfile (filter, title, defname) specify the default file name for the file name field.
  7. ___ = uigetfile (___, 'MultiSelect ', mode) specifies whether the user can select multiple files. The mode is set to 'on' will allow multiple selections. By default, set to 'off'.
    The following example:
[file,path] = uigetfile('*.m');
if isequal(file,0)
   disp('User selected Cancel');
else
   disp(['User selected ', fullfile(path,file)]);
end

Here Insert Picture Description
Output: the User the Selected H: \ Documents \ MyCode \ surf.m

[file,path,indx] = uigetfile;
if isequal(file,0)
   disp('User selected Cancel')
else
   disp(['User selected ', fullfile(path, file),... 
         ' and filter index: ', num2str(indx)])
end

Here Insert Picture DescriptionHere index returned is selected by the arrangement order number of the type name, the figure above index = 3

[file,path] = uigetfile('*.m');

This line of code displays .m files by default, if you want to display .txt files only need to be replaced .txt .m can, if you want to simultaneously display multiple lines of different types of files, use cellular array, for example: { '.m'; 'txt.'; ......}

Here Insert Picture Description


Guess you like

Origin blog.csdn.net/qq_43157190/article/details/89401537