MATLAB: Linebreak between two txt-files in one txt-file.

mergingtxt

I try to add multiple .txt-files to one .txt-file. I would like to have a linebreak after input1 so that input2 start on a new line.
system('type input1.txt > output.txt')
system('type input2.txt >> output.txt')
Kind regards
Kjersti Ensrud

Best Answer

Do you need the slow indirection over a system call?
system('copy /b input1.txt + input2.txt output.txt')
The code in Matlab is a little bit linger, but easier to control:
data = fileread('input1.txt');
if data(end) ~= char(10)
data(end + 1) = char(10);
end
data = [data, fileread('input2.txt')];
[fid, msg] = fopen('output.txt', 'W');
if fid == -1, error(msg); end
fwrite(fid, data, 'char');
fclose(fid);