MATLAB: How to read data from multiple files and save in single file

for loopfprintfread datasavetext;write data

i have 5000 text files each file having(1*50). i need to read those all files from top to bottom order and want to save them in single text file.which should contain all data from those 5000 files(5000*50).

Best Answer

This concatenates the files directly without a conversion to doubles and back again:
pathName = 'C:\Temp';
fileList = dir(fullfile(pathName, '*.txt'));
out = fopen(fullfile(pathName, 'Joined.txt'), 'w');
for k = 1:numel(fileList)
s = fileread(fullfile(pathName, fileList(k).name));
fwrite(out, s, 'char');
end
fclose(out);
Perhaps it is needed to care about a trailing line break:
if s(end) =~ char(10) && s(end-1:end) ~= char([13, 10])
fwrite(out, char(10), 'char'); % Or char([13,10]) ?
end