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: 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 ]
Michelle

Posts: 8
Registered: 5/3/14
Re: Multiple files into Matlab from Excel
Posted: May 6, 2014 5:17 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Steven Lord" <Steven_Lord@mathworks.com> wrote in message <lk86dd$5pb$1@newscl01ah.mathworks.com>...
>
> "Michelle " <mictom@kth.se> wrote in message
> news:lk6rin$n40$1@newscl01ah.mathworks.com...

> > TideMan <mulgor@gmail.com> wrote in message
> > <71a64752-a41e-4205-a72d-70cbd854c5ee@googlegroups.com>...

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

>
> *snip*
>

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

> > 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
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com



Hi,

thanks so much for the help, but I do not understand what you mean by "> 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."



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.