Import multiple text file with one header
8 views (last 30 days)
There are several questions and answers on the site; however, I have a bit of issue by combining several text files.
I have two text files, the first one with headers and the second one without.
I would like to merge them into one file, called 'data' preferably using cell2mat format, and also have a separate variable that shows the headers.
a b c
1 2 3
4 5 6
7 8 9
10 11 12
any help much appreciated!
Michael Haderlein on 11 Aug 2014
will merge the files and add the file names. What do you mean with a separate variable that shows the headers? If you want to store the headers in a variable, you can preallocate the headers before the loop:
then save the first line of each file if there are letters:
fidin=fopen(files(cnt).name); %until here as in the upper code
fwrite(fidout,fread(fidin)); %continue with the upper code