How can i read files inside a folder?
18 次查看(过去 30 天)
显示 更早的评论
Hello ,
i have a folder that contains some .dat file . How can i open this folder and then read(for example) the first 4 .dat files ?
Any help would be valuable .
*i dont need to just diplay the files , i need the actual .dat files to be opened and then work with the data inside them .
0 个评论
采纳的回答
Walter Roberson
2022-1-27
foldername = 'SnowCoverJuly2000';
dinfo = dir( fullfile(foldername, '*.dat') );
dinfo(5:end) = []; %only want first 4
nfiles = length(dinfo);
for K = 1 : nfiles
thisfile = fullfile(dinfo(K).folder, dinfo(K).name);
open(thisfile);
end
You might have problems if you have not installed a third-party program that is registered as being able to open .dat files.
更多回答(1 个)
KSSV
2022-1-27
thepath = 'giveyourpathhere' ;
files = dir([thepath,filesep,'*.dat']) ; % get .dat files in the folder
N = length(files) ; % total dat files present in the folder
for i = 1:N
thisfile = fullfile(files(i).folder,files(i).name) ; % get each file
% load the file
% do what ever you want
end
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!