MATLAB: Does “readcell” fail to read a file via “uigetfile”

filenameMATLABpathuigetfile

I use "uigetfile" to select the file, and then "readcell" to parse it. However, "readcell" does not find the file.
Why does the following code fail to find my file?
filename = uigetfile('*.txt', 'Please select the data file.');
mylist = readcell(filename, 'Delimiter', '');
It shows the following error:
Error using readcell (line 139)
Unable to find or open 'myfile.txt'. Check the path and filename or file permissions.

Best Answer

When using "uigetfile", it returns multiple values. The first one is the filename, and the second value is the path to the file.
You can return the path from that function and use "fullfile" to construct an absolute path to the file. This will be able to load the file correctly.
Solution:
[filename, pth] = uigetfile('*.txt', 'Please select the data file.');
mylist = readcell(fullfile(pth, filename), 'Delimiter', '');