问题
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