Starting in R2017b, you can use the "isfile" function to check if a file exists. For example:
The "isfile" function searches for files only on the specified path or in the current folder.
For R2017a and previous releases, use the "exist" function. For example:
if exist(filename, 'file') == 2
Be sure to specify an absolute path for the file name. The "exist" function searches all files and folders on the search path, which can lead to unexpected results if multiple files with the same name exist.