pre-allocating files
20 views (last 30 days)
Show older comments
This follows a previous post for the following code:
%using a faster method for importing excel
clear all
%obtain the name of each of the folders under investigation
path_name='F:\University\CEH Lancaster\Project\Practice';
TopFolder = path_name;
dirListing = dir(TopFolder);
dirListing=dirListing(3:end);%first 2 are just pointers
for i=1:length(dirListing);
SubFolder{i}=dirListing(i,1).name;
SubFolderPath{i} = fullfile(path_name, dirListing(i,1).name);%obtain the name of each folder
ExcelFile{i}=dir(fullfile(SubFolderPath{i},'*.xls'));%find the .xls files
for j=1:length(ExcelFile{1,i});
ExcelFileName{1,i}{j,1}=ExcelFile{1,i}(j,1).name;%find the name of each .xls file in each folder
end
end
%manually obtain the name of the required worksheets
Name_workbook={'WSB min', 'Bass min sond', 'Ble min', 'Est min'};
%read data in from excel
excel = actxserver('Excel.Application');
excel.Visible=0;
for i=1:length(ExcelFileName);
a(i)=length(ExcelFileName{1,i});
for j=1:a(i);
file{1,i}{j,1}=excel.Workbooks.Open(fullfile(path_name,SubFolder{1,i},ExcelFileName{1,i}{j,1}));
sheet1{1,i}{j,1}=excel.Worksheets.get('Item', Name_workbook(1,i));
MyRange{1,i}{j,1}=sheet1{1,i}{j,1}.UsedRange;
MyData{1,i}{j,1}=MyRange{1,i}{j,1}.Value;
end
end
If the number of Excel files in each cell (1x4 cell) ('ExcelFileName') is 19 19 19 18, how do I pre-allocate a cell array to store the data needed to be imported? pre-allocation is needed as the number of excel files is large.
0 Comments
Answers (0)
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!