Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Import Multiple Excel Files into Multiple files or One Single File
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
ryanshuell@gmail.com

Posts: 128
Registered: 2/11/08
Import Multiple Excel Files into Multiple files or One Single File
Posted: Dec 3, 2012 1:26 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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!!!



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.