How to merge two files into one text file?

不想你离开。 提交于 2020-01-11 14:00:21

问题


I am trying to merge two text output file into one text file .

file 1:

fin=fopen('d://box1.txt','wt');
fprintf(fin,'   Hello \n');

file 2:

fin=fopen('d://box2.txt','wt');
fprintf(fin,'welcome \n');

Any thoughts?


回答1:


I don't think there is a matlab way of doing it easily. But you can use system commands:

Windows:

system(type a.txt b.txt >ab.txt)

Linux:

system(cat a.txt b.txt >ab.txt)

Dont forget to put the path in the files if they are not in your current directory! This works:

fin=fopen('D:\box1.txt','wt');
fprintf(fin,'   Hello \n');
fclose(fin)

fin=fopen('D:\box2.txt','wt');
fprintf(fin,'welcome \n');
fclose(fin)

system('type D:\box1.txt D:\box2.txt >E:\box12.txt')


来源:https://stackoverflow.com/questions/10219140/how-to-merge-two-files-into-one-text-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!