Search code examples
matlabfile-iocell-arraytextscan

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!


Solution

  • 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];