How to read datafiles residing in a different path than the program using the 'load' command or otherwise?

2 vues (au cours des 30 derniers jours)
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)?

Réponse acceptée

Image Analyst
Image Analyst le 26 Jan 2015
Use fullfile() and dir().

Plus de réponses (1)

Thorsten
Thorsten le 26 Jan 2015
Modifié(e) : Thorsten le 26 Jan 2015
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

Catégories

En savoir plus sur Convert Image Type dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by