Suppose there are five text files. Contents of files are textfile1 = i saw an alligator, textfile2 = alligator was sitting near a tree, textfile3 = alligator was sleeping, textfile4 = parrot was flying, textfile5 = parrot was flying.
I have stored the address for each file in a cell-array. How to open those address and then concatenate the strings to form a single cell-array.
-
Have you worked with Matlab before?– SchorschApr 28, 2014 at 17:54
-
Yes, i have worked. But i can't figure out how to store contents from different textfiles to a single cell array.– user3416063Apr 28, 2014 at 17:58
Add a comment
|
1 Answer
If you have a cell array called files you could use:
txt = cell(0);
for i=1:length(files)
txt = [txt,fileread(files{i})];
end
The cell array txt
will have the same number of elements as files
and with each element holding the text from that file.