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.

추가 답변 (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