How to read datafiles residing in a different path than the program using the 'load' command or otherwise?
조회 수: 1 (최근 30일)
이전 댓글 표시
My matlab code wherein I read the datafiles (filename format: datafile_XX.dat, XX is the serial number of the file) using the 'load' command sits in the directory D:/, while my datafiles reside in the path F:/TP/Data/day. How to make my program read the datafiles (in a loop) sitting in a different path using the load command (or there is any other convenient command that helps)?
댓글 수: 0
채택된 답변
Image Analyst
2015년 1월 26일
Use fullfile() and dir().
Code samples are in the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
댓글 수: 0
추가 답변 (1개)
Thorsten
2015년 1월 26일
편집: Thorsten
2015년 1월 26일
srcdir = 'F:/TP/Data/day'
for i = 1:10
fullfilename = [srcdir filesep 'datafile_' int2str(i) '.dat'];
% if the file are labels with leading '0', like 01, 02, 03, use
% fullfilename = [srcdir filesep 'datafile_' sprintf('%02d', i) '.dat'];
% and if the files are labeled with two leading '0', like 001, 002, 003, ...
% replace '%02d' with '%03d' etc.
load(fullfilename)
% do something with the loaded variables
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!