open .mat files and concatenate their matrix contents

1 Ansicht (letzte 30 Tage)
James
James am 29 Jun. 2012
Hi,
I will like to open many .mat files (sequentially named file_0.mat, file_1.mat,.....file_50.mat), and then concatenate (vertically and sequentially) the matrix data (about 2 million rows by 50 columns) into one variable available in the workspace accessible to other programs.
How can I write matlab codes to carry out this processes?
Thanks
James

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 29 Jun. 2012
  4 Kommentare
James Tursa
James Tursa am 29 Jun. 2012
IMO that is not a good way to do this in general. At every iteration in the loop you need to copy all of the data to a new memory block to do the concatenation. This drags performance. What I would do is read each iteration into an element of a cell array. Then after all of the files have been read concatenate all of the cell array contents into the big matrix. That way the data only gets copies once, not many times during the file reading iterations.
James
James am 30 Jun. 2012
Thanks Walter. It worked! I appreciate James' comment about efficiency, and I tried to implement the codes as follows:
matData = [];
for k = 0:2
matFilename = sprintf('mut%d.mat',k);
matLoad = load(matFilename);
similar = cell(size(matLoad.(num2str(k, 'mut%d'))));
end;
matData = [matData; similar];
But, I'm not sure if this what you meant.
James

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by