Your screenshots clearly show that the current directory is C:\Program Files\MATLAB. The Program Files directory is a system directory on Windows. Under no circumstances should you put data files such as your m files and excel files in there. Matlab should have created a matlab directory for you in your My Documents folder. Work in there instead.
Recent versions of Windows, such as the one you're using, will actively prevent you putting data in Program Files to the point of lying to you. It may tell you that you've saved a file in there whereas it actually has saved it in a virtual store in another location. This may be the reason matlab can see the files in some circumstances and not others (depends on how it tries to access the files). So as said, put your code and excel file in My Documents
As to reading the Excel file, use the full path of the file instead of just the file name. It'll be more reliable, means the excel file doesn't have to be in the same directory as your code and means you don't have to manipulate matlab's path.
4 Comments
Adam (view profile)
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/353198-why-can-t-matlab-access-a-file-that-is-in-its-current-directory#comment_477974
Fahad (view profile)
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/353198-why-can-t-matlab-access-a-file-that-is-in-its-current-directory#comment_477981
Stephen Cobeldick (view profile)
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/353198-why-can-t-matlab-access-a-file-that-is-in-its-current-directory#comment_477991
Steven Lord (view profile)
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/353198-why-can-t-matlab-access-a-file-that-is-in-its-current-directory#comment_767416
Sign in to comment.