writing a matrix of data contained in multiple file into a text file and saving as new text files

3 次查看(过去 30 天)
I have a folder containing 5000 text files having 48*3 data set as the content. I haev a text file where i ant to overwrite the content of these 5000 files individually to generate a new set of output files.

回答(1 个)

Nilanshu Ranjan
Nilanshu Ranjan 2022-11-3
I understand that you want to perform two tasks. First, you want to combine the data from 5000 text files into a single text file, perform some operations and then split the text file into new output files.
For both the tasks, you can use fprintf() function. Remember to open and close files using fopen() and fclose() . When using fopen() on a file that is not present in the path, MATLAB will create a new file.
A = [1 2; 3 4];
fid = fopen('file.txt','w');
fprintf(fid,'%d %d \n',A);
fclose(fid);
If you want to override textfiles you may use writematrix() function.
For more information check the documentation on fprintf(), writematrix(), fopen(), fclose().

类别

Help CenterFile Exchange 中查找有关 Low-Level File I/O 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by