开发者

How to read multiple files into a single cell array?

I have a large dataset split into 5 files (each has 15000 attributes, first file contains header (attribute names) and 9999 records, and the other 4 contain 10000 records).

Using textscan, I have created 5 cell arrays which have to be merged and don't know whether this approach is appropriate or it would be better to directly read all 5 files into single cell array开发者_运维百科. Anyway I would be thankful if anyone of you could show the way to merge several cell arrays into single cell array or read several text files into single cell array.

Thank you!


Unless you want to do some Java magic, you cannot read multiple files into a single array directly.

However, once you have obtained the cell arrays, it should be easy to combine them: Assuming that there are the same number of columns in each cell array, you can concatenate them like this:

finalCell = [cell1;cell2;cell3;cell4;cell5];


Expanding on Jonas' answer, If memory is a concern, you could combine them as you read the files to avoid having 5 x 15000 x 10000 + 1 15000 x 50000 cell arrays.

finalCell = textscan(fid_1,'format');

finalCell = [finalCell; textscan(fid_2,'format')];

finalCell = [finalCell; textscan(fid_3,'format')];

finalCell = [finalCell; textscan(fid_4,'format')];

finalCell = [finalCell; textscan(fid_5,'format')];

Best Regards,

Adam

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜