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:
concatenating data files

Subject: concatenating data files

From: Kyle

Date: 11 May, 2010 17:16:08

Message: 1 of 4

Hello,

I have several data files that are all discrete parts of the same sample space and I need to concatenate them all into one big array. For example, we might have the following two files:

data1.dat:
1 1
2 2
3 3
4 4
5 5

data2.dat
6 6
7 7
8 8
9 9
10 10

and I need to import them into matlab into a variable that will have the value

1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10


now, I can easily import each one separately using importdata, on each one, but then i have two variables. How can I combine them into one?

Subject: concatenating data files

From: Sean

Date: 11 May, 2010 17:44:06

Message: 2 of 4

"Kyle " <kbrig035@uottawa.ca> wrote in message <hsc3co$id0$1@fred.mathworks.com>...
> Hello,
>
> I have several data files that are all discrete parts of the same sample space and I need to concatenate them all into one big array. For example, we might have the following two files:
>
> data1.dat:
> 1 1
> 2 2
> 3 3
> 4 4
> 5 5
>
> data2.dat
> 6 6
> 7 7
> 8 8
> 9 9
> 10 10
>
> and I need to import them into matlab into a variable that will have the value
>
> 1 1
> 2 2
> 3 3
> 4 4
> 5 5
> 6 6
> 7 7
> 8 8
> 9 9
> 10 10
>
>
> now, I can easily import each one separately using importdata, on each one, but then i have two variables. How can I combine them into one?


>>datatotal = [data1; data2]; %Note the semi colon that's the vertical concatenation operator

Subject: concatenating data files

From: Kyle

Date: 11 May, 2010 17:49:20

Message: 3 of 4

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <hsc516$3g7$1@fred.mathworks.com>...
> "Kyle " <kbrig035@uottawa.ca> wrote in message <hsc3co$id0$1@fred.mathworks.com>...
> > Hello,
> >
> > I have several data files that are all discrete parts of the same sample space and I need to concatenate them all into one big array. For example, we might have the following two files:
> >
> > data1.dat:
> > 1 1
> > 2 2
> > 3 3
> > 4 4
> > 5 5
> >
> > data2.dat
> > 6 6
> > 7 7
> > 8 8
> > 9 9
> > 10 10
> >
> > and I need to import them into matlab into a variable that will have the value
> >
> > 1 1
> > 2 2
> > 3 3
> > 4 4
> > 5 5
> > 6 6
> > 7 7
> > 8 8
> > 9 9
> > 10 10
> >
> >
> > now, I can easily import each one separately using importdata, on each one, but then i have two variables. How can I combine them into one?
>
>
> >>datatotal = [data1; data2]; %Note the semi colon that's the vertical concatenation operator



Thank you, and how about horizontal concatenation?

Subject: concatenating data files

From: Godzilla

Date: 12 May, 2010 02:47:04

Message: 4 of 4

"Kyle " <kbrig035@uottawa.ca> wrote in message <hsc5b0$mee$1@fred.mathworks.com>...
> "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <hsc516$3g7$1@fred.mathworks.com>...
> > "Kyle " <kbrig035@uottawa.ca> wrote in message <hsc3co$id0$1@fred.mathworks.com>...
> > > Hello,
> > >
> > > I have several data files that are all discrete parts of the same sample space and I need to concatenate them all into one big array. For example, we might have the following two files:
> > >
> > > data1.dat:
> > > 1 1
> > > 2 2
> > > 3 3
> > > 4 4
> > > 5 5
> > >
> > > data2.dat
> > > 6 6
> > > 7 7
> > > 8 8
> > > 9 9
> > > 10 10
> > >
> > > and I need to import them into matlab into a variable that will have the value
> > >
> > > 1 1
> > > 2 2
> > > 3 3
> > > 4 4
> > > 5 5
> > > 6 6
> > > 7 7
> > > 8 8
> > > 9 9
> > > 10 10
> > >
> > >
> > > now, I can easily import each one separately using importdata, on each one, but then i have two variables. How can I combine them into one?
> >
> >
> > >>datatotal = [data1; data2]; %Note the semi colon that's the vertical concatenation operator
>
>
>
> Thank you, and how about horizontal concatenation?

[data1 data2]
but only if the number of rows is the same in each file

Tags for this Thread

No tags are associated with 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