how to merge text files
2 次查看(过去 30 天)
显示 更早的评论
for k = 1:100
fname = ['Image' num2str(k) '.txt'];
fid = fopen(fname,'wt');
for j=1:length(R)
fprintf(fid,'%f %f %f\n',R(j),C(j) ,Z(j));
end
fclose(fid);
end
I got 100 text files from this code, In it R,C,Z will be saved as columns.. Now, i want to merge all this text files in single text file as R,C,Z columns.. so, how to do..?
0 个评论
采纳的回答
Walter Roberson
2012-11-8
OS-X and Linux version:
!cat Image???.txt > all_Image.txt
No point in writing code when the operating system already has the facilities.
3 个评论
Walter Roberson
2012-11-8
编辑:Walter Roberson
2012-11-8
I misread your code and thought you were using 001 and so on. The correction would be
!cat Image*.txt > all_Image.txt
How you calculated the values in the vectors (e.g., by processing .JPG files) is not important to the task of merging the text files.
Each time you start up xlsread() or xlswrite() a new ActiveX connection is made to Excel (if you are using MS Windows.) That is slow. Your code for doing the appending is also pretty inefficient, writing to the xls file and reading it back immediately.
outfid = fopen('all_Image.txt', 'wt');
for j = 1 : 100
filename = ['Image' num2str(j),'.txt'];
fwrite(outfid, fileread(filename));
end
fclose(outfid)
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!