문제

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top