1

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.

2
  • Have you worked with Matlab before?
    – Schorsch
    Apr 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. Apr 28, 2014 at 17:58

1 Answer 1

3

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.

1
  • Thank you Sir, it was a great help. Solved most of the problem. Apr 28, 2014 at 18:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.