MATLAB: Error in downloading sequence of txt files

txt files download sequence

Hello, I have a sequence of txt files, similar to the one attached, in a folder called 'runfiles'. I am using the code below to these files one by one. However, I am getting an error message. I have tried the same code with other txt files and it worked. Could you please tell me how I can fix this?-Thanks,K.
>>>>>>>ERROR MESSAGE:
"Error using load Unable to read file AbR1997.txt: No such file or directory.
Error in TSaddmissrowsNonLEAP (line 6) ALL=load(filename) %load the file to work with it"
>>>>>>>>CODE USED:
matfiles = dir(fullfile('N:', 'My Documents', 'MATLAB','runfiles', '*.txt'))%go to the folder where you have the files
for n=1997:1999% @@@@@
filename = ['AbR', int2str(n), '.txt'] % @@@@@'sdfhbx' this is the text in the name of the filename that is followed by the sequencial number which is 'i'
ALL=load(filename) %load the file to work with it
end

Best Answer

Katerina - are you running the code from the directory where those files are located, or some other directory? Is the directory that contains the files in your MATLAB search path?
If a file is in a directory/folder that is in the MATLAB search path, then you will be able to open (or load) that file by simply providing the file name, as you are doing with
ALL=load(filename)
But if the directory/folder for this file is not in the MATLAB search path, then the code will not be able to find that file and you will see the
Error using load
Unable to read file 'AbR1997.txt': no such file or directory.
You can do a couple of things - either add the directory (that contains these files) to the MATLAB search path, or better, just specify where the file is located. If we assume that your directory is N:/My Documents/MATLAB/runfiles, then build the folder name as
foldername = fullfile('N:', 'My Documents', 'MATLAB','runfiles');
and use this when we build the file name
for n=1997:1999
% @@@@@'sdfhbx' this is the text in the name of the filename that is
% followed by the sequencial number which is 'i'
filename = fullfile(foldername,['AbR', int2str(n), '.txt']);
%load the file to work with it
ALL=load(filename)
end
Try the above and see what happens!