how read data from different folders ?

1 回表示 (過去 30 日間)
pruth
pruth 2016 年 2 月 11 日
コメント済み: pruth 2016 年 2 月 14 日
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?
pruth
pruth 2016 年 2 月 14 日
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.
  1 件のコメント
pruth
pruth 2016 年 2 月 14 日
thank u ..... :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by