The Math Forum

Search All of the Math Forum:

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

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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

Advanced Search

Back to Topic List Back to Topic List

Posts: 150
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, {}'); %'

%# 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);

%# 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);

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).


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

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.