how read data from different folders ?

1 vue (au cours des 30 derniers jours)
pruth
pruth le 11 Fév 2016
Commenté : pruth le 14 Fév 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 commentaires
Geoff Hayes
Geoff Hayes le 13 Fév 2016
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?
pruth
pruth le 14 Fév 2016
all subfolders of brodata.

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 14 Fév 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.
  1 commentaire
pruth
pruth le 14 Fév 2016
thank u ..... :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur File Operations 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