Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Import Multiple Excel Files into Multiple files or One Single File

Subject: Import Multiple Excel Files into Multiple files or One Single File

From: Ryan

Date: 3 Dec, 2012 18:26:11

Message: 1 of 1

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

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us