MATLAB Answers

how read data from different folders ?

8 views (last 30 days)
pruth
pruth on 11 Feb 2016
Commented: pruth on 14 Feb 2016
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 Comments
pruth
pruth on 14 Feb 2016
all subfolders of brodata.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 14 Feb 2016
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.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!