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:
manipulating structures

Subject: manipulating structures

From: axle

Date: 25 Mar, 2011 09:41:04

Message: 1 of 2

Hey,

Im new to matlab and i was wondering if I could have some opinions on my approach. Here goes - im working with data contained in multiple '.mat' files. The data is of the struct format. I need to read all this data into matlab and put it into a new struct . I should say that there could be as many as a 100,000 mat files at some point.

heres how i plan to do this
- put the mat file names into a variable
- use a for loop and the 'eval' function to read each file in - and put it into the new struct under the correct heading(based on one of the fields in the mat data files ).

the whole process seems to be rather resource intensive. it takes 20 minutes to just load all the files - I have not tried sorting them as yet. Is there a better way to do this? your opinions are highly appreciated!

Subject: manipulating structures

From: Steven_Lord

Date: 25 Mar, 2011 13:39:02

Message: 2 of 2



"axle " <andrefernandez85@yahoo.co.in> wrote in message
news:imhnvg$g1c$1@fred.mathworks.com...
> Hey,
>
> Im new to matlab and i was wondering if I could have some opinions on my
> approach. Here goes - im working with data contained in multiple '.mat'
> files. The data is of the struct format. I need to read all this data into
> matlab and put it into a new struct . I should say that there could be as
> many as a 100,000 mat files at some point.
>
> heres how i plan to do this
> - put the mat file names into a variable
> - use a for loop and the 'eval' function to read each file in

Do not do this.

Use LOAD with an output argument instead:

thefile = load(matFileName);

If the MAT-file contained a variable x you can now refer to that variable as
thefile.x. Dynamic field names may also help you do what you want.

s = 'x';
thefile.(s) % returns x from the MAT-file.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

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