Error in downloading sequence of txt files
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (1)
Gitesh Nandre
el 5 de Sept. de 2014
It appears that those text files are not in your current directory. In your code, you neither switch to the directory where text files are stored nor you specify the full path for files while loading them. You can achieve it in following way:
%get directory name
directory = fullfile('N:', 'My Documents', 'MATLAB','runfiles');
%get text file info for text files starting with 'AbR'
matfiles = dir(fullfile(directory, 'AbR*.txt'));
for filenum = 1:numel(matfiles)
%load the text files in workspace
load([directory '\' matfiles(filenum).name]);
end
Categorías
Más información sobre Downloads en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!