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: How to Import Several Text Files Into Matlab?
Replies: 4   Last Post: Nov 25, 2012 9:21 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
ryanshuell@gmail.com

Posts: 128
Registered: 2/11/08
Re: How to Import Several Text Files Into Matlab?
Posted: Nov 25, 2012 8:51 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Wow! Thanks so much! The second script worked perfect!! I'm not sure about the first one though. It ran, but it didn't seem to do anything useful. All it did was give me this:
<9x1 cell> <9x1 cell> <9x1 cell>

Thanks again!!


dpb <none@non.net> wrote in message <k8u508$mov$1@speranza.aioe.org>...
> On 11/25/2012 1:37 PM, dpb wrote:
> > On 11/25/2012 1:30 PM, Ryan wrote:
> >> Ok, I give up. I?ve searched online for hours for a script that will
> >> import several Text files in a folder into a single variable in Matlab.
> >> I have a script that imports several Text files into several variables
> >> in Matlab, but I can?t figure out how to import several Text files into
> >> a single variable. Does anyone know how to do this?

> >
> > concatenate the second onto the first, the third onto that, etc., etc., ...

>
> or, use a cell array.
>
> To read all files that match *.txt--
>
> d = dir('*.txt');
> nfiles = length(d);
> data = cell(1, nfiles);
> for k = 1:nfiles
> data{k} = importdata(d(k).name);
> end
>
> Above is cell array...can handle case where not all files have same
> shape of input. If all have same number of columns and want a single
> array, then just replace the cell reference w/ concatenation but be
> aware that the dynamic reallocation may become slow w/ a large number of
> and/or very large files...
>
> d = dir('*.txt');
> nfiles = length(d);
> data = [];
> for k = 1:nfiles
> data = [data; importdata(d(k).name)];
> end
>
> --




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.