Error in downloading sequence of txt files
이전 댓글 표시
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
채택된 답변
추가 답변 (1개)
Gitesh Nandre
2014년 9월 5일
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
카테고리
도움말 센터 및 File Exchange에서 Downloads에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!