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: Multiple files into Matlab from Excel
Replies: 15   Last Post: May 9, 2014 2:06 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Steven Lord

Posts: 2,237
Registered: 9/26/13
Re: Multiple files into Matlab from Excel
Posted: May 5, 2014 10:13 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Michelle " <> wrote in message
> TideMan <> wrote in message
> <>...

>> On Monday, May 5, 2014 1:10:07 AM UTC+12, Michelle wrote:
>> > "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message
>> > <lk5cqf$8di$>...


>> Show us the code you tried that didn't work.
> Thanks,
> source_dir='/Users/MichelleTommosgard/Desktop/test';
> source_files=dir(fullfile(source_dir,'*.xlsx'));
> n=length(source_files);
> i=n;

Unnecessary. The variable i will be overwritten when you start your FOR

> a=cell(n);

This creates an n-by-n cell array which will do what you want, but is
overkill. Try cell(1, n) or cell(n, 1) instead.

> for i=1:n
> if i<=n

Unnecessary. By the way you've written your FOR loop, i will ALWAYS be less
than or equal to n.

> a{i}=xlsread(source_files(i).name)
> split=strsplit(source_files(i))

Why are you doing this? For one thing, you never use the variable split
later in the loop. For another, this will attempt to split _a field of the
source_files struct array_ and so will probably error out.

> aa{1+i}.data=xlsread(source_files(i+1).name);

Again, why? While it is possible to mix cell arrays and struct arrays, that
can get complicated really quickly. I recommend you stick with using cell
arrays alone.

> end

Unnecessary, since you're going to remove the IF statement in this loop and
this is the END associated with the IF.

> end

After this, the contents of the file whose name is source_files(k).name is
in a{k}.

Steve Lord
To contact Technical Support use the Contact Us link on

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.