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

Posts: 150
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 <> wrote in message <k8u508$mov$>...
> 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]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.