how read data from different folders ?

2 次查看(过去 30 天)
hello i have written code attaching bellow, i can read data from single folder by giving a path. but i dont know what syntax i can use to read all data. please give me any method so i can read all data from all sub folders and can use bellow code on them,
g
clear all
close all
clc
initialdir = cd();
folder = 'E:\brodata\2011\01\01';
outputfolder = 'E:\20';
cd(folder);
temp = dir();
brofilenames = [];
flag_1 = 0 ;
for i = 1:numel(temp);
if (strncmp(temp(i).name, '.', 1) == 1);
flag_1 = flag_1 +1 ;
else
brofilenames{i-flag_1} = temp(i).name ;
end
end
filetime = nan(size(brofilenames,2),1);
broperday= cell(size(brofilenames,2),1);
for file = 1:size(brofilenames,2)
fname = char(brofilenames(file)); % to make the file name a character array
if (size(fname,2)==84)
filetime(file) = datenum(fname(end-42:end),'yyyymmddHHMMss')
end
file_id = H5F.open(fname) ;
BrO_data = h5read(fname,'/TOTAL_COLUMNS/BrO'); % to read BrO data
centrelat_data = h5read(fname,'/GEOLOCATION/LatitudeCentre' );% to read latitude values
centrelon_data = h5read(fname,'/GEOLOCATION/LongitudeCentre' );% to read longitude values
data = numel(BrO_data);
H5F.close(file_id);
tempdata = nan(numel(BrO_data),3);
for i = 1:numel(BrO_data)
tempdata(i,1)= centrelat_data(i);
tempdata(i,2)= centrelon_data(i);
tempdata(i,3)= BrO_data(i);
end
broperday{file} = tempdata;
end
for i = 1:size(broperday,1)
broperday{i,2} = filetime(i,1);
end
cd(outputfolder)
save('broperday.mat', 'broperday');
  2 个评论
Geoff Hayes
Geoff Hayes 2016-2-13
pruth - is this the example folder?
folder = 'E:\brodata\2011\01\01';
Are you just interested in all subfolders of 2011 or all subfolders of brodata?

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2016-2-14
See my attached code. It uses genpath() to generate a list of all folders within a top level folder that you specify, Then it gets a list of all files according to some file pattern that you specify. Once you have the file name, you can process it however you wish.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by