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
No products are associated with this question.
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.
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
0 Comments