loops - merging and manupulating files in matlab -
is there way run loop through folder , process 30 files month , give average,max of each columns , write in 1 excel sheet or so??
i have 30 files of size [43200 x 30]
ran different matlab scrip generate them names easy file_2010_04_01.xls , file_2010_04_02.xls ..... , on cannot merge them each 20mbs , matlab crash. ideas? thanks
you can first list of files using function dir. here's example:
dirdata = dir('file_2010_04_*.xls'); %# match file names wildcard datafiles = {dirdata.name}; %# file names in cell array
once have these files, can loop on them using xlsread load data. note xlsread can return different versions of data in excel file:
[numdata,txtdata,rawdata] = xlsread(filename); %# filename string
here, numdata
contains cells numeric data in file, txtdata
contains cells text data in file, , rawdata
cell array contains of data in file. have determine data array use , how index 43200-by-30 matrix of data process.
putting together, here's code sample how process data column maxima , column averages across of files:
columntotal = zeroes(1,30); %# initialize column sum columnmax = -inf(1,30); %# initialize column maxima dirdata = dir('file_2010_04_*.xls'); %# match file names in current folder datafiles = {dirdata.name}; %# file names in cell array nfiles = numel(datafiles); %# number of files ifile = 1:nfiles %# loop on files numdata = xlsread(datafiles{ifile}); %# load data %# here, i'm assuming "numdata" contains 43200-by-30 matrix columntotal = columntotal+sum(numdata); %# add column data columnmax = max(columnmax,max(numdata)); %# column maxima end columnaverage = columntotal./(nfiles*43200); %# average across files
Comments
Post a Comment