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 Several Hundred .txt files

Subject: Import Several Hundred .txt files

From: Robbie Brady

Date: 12 Jun, 2012 18:54:08

Message: 1 of 4

Hello,

I am currently trying to load 726 .txt files into Matlab, ultimately to vertically concatenate them into one array, ideally in a 3D matrix of dimensions 65 x 1 x 726.

The files are named:

DSpec1203190348
DSpec1203190548
DSpec1203190748
etc etc

So that there is effectively a step of 200 in the file name between each file. I should also mention that the first 3 rows of each file is text- this is written by the program they were created in (Wavesmon) and cannot be changed unfortunately, although I think textscan would be useful here. Beyond this, the file is 65x1.

Any help would be massively appreciated, as this has got me well and truly stumped.

Many thanks,

Robbie

Subject: Import Several Hundred .txt files

From: Pekka Kumpulainen

Date: 13 Jun, 2012 12:13:07

Message: 2 of 4

"Robbie Brady" <robbie.brady@postgrad.plymouth.ac.uk> wrote in message <jr838g$eec$1@newscl01ah.mathworks.com>...
> Hello,
>
> I am currently trying to load 726 .txt files into Matlab, ultimately to vertically concatenate them into one array, ideally in a 3D matrix of dimensions 65 x 1 x 726.
>
> The files are named:
>
> DSpec1203190348
> DSpec1203190548
> DSpec1203190748
> etc etc
>
> So that there is effectively a step of 200 in the file name between each file. I should also mention that the first 3 rows of each file is text- this is written by the program they were created in (Wavesmon) and cannot be changed unfortunately, although I think textscan would be useful here. Beyond this, the file is 65x1.
>
> Any help would be massively appreciated, as this has got me well and truly stumped.
>
> Many thanks,
>
> Robbie

"Processing a Sequence of Files" in the documentation:
http://www.mathworks.com/help/techdoc/import_export/br5wz4t.html#br7q_u6

Subject: Import Several Hundred .txt files

From: Kirsten

Date: 10 Sep, 2012 20:09:08

Message: 3 of 4

If you're still wondering, you can use something like this:
name = 'DSpec';
ext = '.txt';
number=1203190348
for i=2:726
number(i) = number(i-1)+200;
end

Then create another for loop to read all the files and create a filename in each iteration of the loop
filename=strcat(name, num2str(number(i)), ext);
In most of the reading functions you can just use filename or perhaps use fopen first.

"Robbie Brady" <robbie.brady@postgrad.plymouth.ac.uk> wrote in message <jr838g$eec$1@newscl01ah.mathworks.com>...
> Hello,
>
> I am currently trying to load 726 .txt files into Matlab, ultimately to vertically concatenate them into one array, ideally in a 3D matrix of dimensions 65 x 1 x 726.
>
> The files are named:
>
> DSpec1203190348
> DSpec1203190548
> DSpec1203190748
> etc etc
>
> So that there is effectively a step of 200 in the file name between each file. I should also mention that the first 3 rows of each file is text- this is written by the program they were created in (Wavesmon) and cannot be changed unfortunately, although I think textscan would be useful here. Beyond this, the file is 65x1.
>
> Any help would be massively appreciated, as this has got me well and truly stumped.
>
> Many thanks,
>
> Robbie

Subject: Import Several Hundred .txt files

From: Olivier

Date: 11 Oct, 2012 22:48:08

Message: 4 of 4

If I have a sequence of yearly time series data sets (data1998.mat data1999.mat ... data2009.mat), which contain the same variable names, and load them sequentially, like this:

files = dir('C:\Timeseries\data*.mat);
for i = 1:length(files)
    eval(['load ' files(i).name, ' time counts']);
end

... how can I concatenate/append the variables 'counts' from each file sequentially (in the for loop above, for instance) in the 'time' dimension, given that certain yearly data sets do not necessarily begin on Jan-1-YYYY, end on Dec-31-YYYY, or are missing altogether?

Tags for 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