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: 26 Nov, 2012 05:06:06

Message: 1 of 2

I was fiddling around with the code below:
cd('C:\Users\Excel\Desktop\Excel_Files')
d = dir('*.xls');
nfiles = length(d);
data = [];
for k = 1:nfiles
   num = xlsread(d(k).name);
end

It seems to import all files, but overwrites the data in the file, so only the last file imported is actually stored in the Matlab variable.

I am trying to figure out a way to import multiple files into multiple Matlab variables.
Also, I am trying to figure out a way to import multiple files into one single Matlab variable.

Can someone here give me the code to do that?

Thanks!!

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

From: Nasser M. Abbasi

Date: 26 Nov, 2012 05:34:50

Message: 2 of 2

On 11/25/2012 11:06 PM, Ryan wrote:
> I was fiddling around with the code below:
> cd('C:\Users\Excel\Desktop\Excel_Files')
> d = dir('*.xls');
> nfiles = length(d);
> data = [];
> for k = 1:nfiles
> num = xlsread(d(k).name);
> end
>
> It seems to import all files, but overwrites the data in the file, so only the last
>file imported is actually stored in the Matlab variable.
>

Well. Yes. That is what you telling Matlab to do. You are
writing

         num = xlsread(d(k).name);

And Matlab is doing just that. It puts the content of d(k).name
into num.

see recent thread 'Re: How to Import Several Text Files Into Matlab?'

may be that will help.

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