|
Now, the code below seems ok to me, but when I run it, I get this error:
Error in read_all_files_in_folder (line 27)
xlswrite(fOut, numData, s);
numData: empty 0x0 double
%folders = {'C:\Users\Excel\Desktop\Excel_Files\'};
%# get input XLS files
dName = uigetdir('.', 'Select folder containing Excel XLS files');
if dName==0, error('No folder selected'); end
files = dir( fullfile(dName,'*.xls') );
files = strcat(dName, filesep, {files.name}'); %'
%# prepare output XLS file
[fName dName] = uiputfile({'*.xls' 'Excel (*.xls)'}, 'Output File', 'final.xls');
if dName==0, error('No file selected'); end
fOut = fullfile(dName,fName);
%# process
NUM_SHEETS = 1; %# number of sheets per file
for s=1:NUM_SHEETS
%# extract contents of same sheet from all files
numData = cell(numel(files),1);
for f=1:numel(files)
numData{f} = xlsread(files{f}, s);
end
%# rearrange data
numData = cat(3,numData{:});
numData = reshape(permute(numData,[3 1 2]), [], size(numData,2));
%# write data to corresponding sheet of output XLS file
xlswrite(fOut, numData, s);
end
How can I modify this code to import all files in the folder into separate variables (any number of Excel files become any number of Matlab variables)? Also, how can I make the code import everything into one single variable (all data in files 2 - n is appended onto the data in file 1. This would be like a Union Query in a database).
THANKS!!!
|