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:
Reading multiple .mat files and joining variables

Subject: Reading multiple .mat files and joining variables

From: gregoire

Date: 27 Apr, 2009 17:56:02

Message: 1 of 2

I cannot seem to find a suitable general and quick solution to the following problem:-

In a directory, I have a certain variable number of mat files, all of which contain the same 2 variables x and y, which are matrices.

For example, in the first mat file I would say have:-

x:
1 2 3
2 3 4
2 5 6
and in the second I have
x:
0 0 0
0 0 0
0 0 0
2 3 4
2 3 4
1 2 3

This is due to different computers processing different sets of rows of the matrix

THE FINAL TOTAL number of rows is always known if it helps, or it can be found from looking at the number of rows in the final .mat file (which I would prefer), the width does not change either.

Is there a fast way to read in all the .mat files in a directory and join all the matrix variables from all the mat files, so I end up with one x variable stating:-

x:
1 2 3
2 3 4
2 5 6
2 3 4
2 3 4
1 2 3

Thank you!
greg

Subject: Reading multiple .mat files and joining variables

From: dpb

Date: 27 Apr, 2009 18:27:35

Message: 2 of 2

gregoire wrote:
...
> Is there a fast way to read in all the .mat files in a directory and
> join all the matrix variables from all the mat files, so I end up
> with one x variable stating:-
>
...

use dir() to return the names and then a loop.

You can simply concatenate each submatrix to a larger.

Don't believe there's a prebuilt routine but it's simply stringing a few
calls together.

--

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