saving variables in a single .mat file

Hello,
I have 360 .mat files containing same variable in with different data (row vectors) each of size in(1x3800000) stored in them. They are of size 9.84GB (all 360 files).
Now I want to save them all in 1 .mat file as a matrix out(360x3800000).
How can I do it?

2 Kommentare

Daniel Shub
Daniel Shub am 26 Mär. 2012
What problems are you running into?
zozo
zozo am 26 Mär. 2012
I need to extract some data from each of these 360 files(row vectors) and do further processing. So, I do not want to load them 1 by 1,extract data, load again and so on. Having them all together in a cell/array makes it far easier.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

ndiaye bara
ndiaye bara am 26 Mär. 2012

0 Stimmen

Try this code m=zeros(3800000,360); for k=1:360, eval(sprintf('load F*_%d.mat',k)); % F*=name of all your files .mat% eval(sprintf('y=F*_%d(:,1);',k)); disp(k); clear F* if k==1, m=y; else m=[m,y]; end end
save File m t %save the new file .mat

4 Kommentare

Jan
Jan am 26 Mär. 2012
Please format the code and avoid EVAL for this task. EVAL is really not useful here. The pre-allocation of m does not help also if you let the martrix grow inside the loop.
Creating a 3800000x360 doublke matrix will be a problem on a 4GB machine.
zozo
zozo am 26 Mär. 2012
@Jan: so what should be the edited code be in my case (for variable 'in'? I have problems running the code suggested by @ndiaye.
zozo
zozo am 27 Mär. 2012
Same variable 'in' was saved each time, but with different file names as data(1).mat,data(2).mat,data(3).mat.......data(360).mat
Please suggest the syntax for my case.
Jan
Jan am 27 Mär. 2012
Dear zozo, accepting an answer means, that it solves your problem.
Daniel and I have warned you that you cannot load a 11GB of data (360*3800000*8 byte per double) efficiently, if you have only 4GB of RAM. I assume you need 32GB RAM to work efficiently with such large data, 64GB is safer.
The above EVAL approach is cruel.
You currently did not specify in which format you want to store the data, DOUBLEs or SINGLEs, an integer type, as cell or matrix. Anyhow, I'm convinced, that it is the wrong approach due to the limited memory.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Jan
Jan am 26 Mär. 2012

0 Stimmen

Do you have a 64-bit Matlab version? How many RAM do you have installed? Do you want to store the values in one 360 x 3'800'000 array, a most likely more useful 3'800'000 x 360 array, of as separate vectors e.g. in a {1 x 360} cell. The later has the advantage, that it does not need a contiguos free block of memory.

4 Kommentare

zozo
zozo am 26 Mär. 2012
Yes, I have 64-bit Matlab version and my RAM is 4GB. Yes, which ever is efficient and compatible(my RAM holds). What the syntax for saving as {1x360} cell ?
Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran am 26 Mär. 2012
Hi Jan,
I have a doubt in the mat file, which is present in image retrival project in file exchange of mathworks. It has 651 images in their database. The mat file has been splitted into two categories. files and Hists.. How to create two things in a mat file.
Regards,
siva
siva@sdatech.in
Jan
Jan am 26 Mär. 2012
4GB RAM is very lean for such a big chunk of data. If it is really necessary to keep all values in the RAM simultaneously, buy more RAM. Implementing workarounds to process the data in pieces will be more expensive.
Jan
Jan am 26 Mär. 2012
@Siva: Does you comment concern the current topic? If so, please explain the connection. If not, please delete the comment and post it as a new question - with more details. Thanks.

Melden Sie sich an, um zu kommentieren.

Daniel Shub
Daniel Shub am 26 Mär. 2012

0 Stimmen

In a comment to Jan you say you have 4 GB of RAM. Loading 9+ GB of data is going to bring your computer to a screeching halt.
Try and create an array of the required size and see what happens ...
x = randn(360, 38000000);

2 Kommentare

zozo
zozo am 26 Mär. 2012
Yes, I think I will load 7x(50x3800000)+10 at a time. But Iam having problem loading them into 1 file as suggested by @ndiaye
Daniel Shub
Daniel Shub am 27 Mär. 2012
Why? Nobody wants a 1+GB data file. Leave the files small and load them as needed. I doubt there is much of a benefit of doing a single huge load.

Melden Sie sich an, um zu kommentieren.

Kategorien

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by