use matlab to process a txt file
Show older comments
The situation is this. There is a txt file generated by a scientific software containing lots of information line by line. Some parameters are not optimized well by that software and thus I have to optimize them in matlab. Then I have to make a another txt file the same as the previous one except some parameters are not the same.
So the main task is to use the matlab function 'fprint' to print the content of the txt file. For instance, the txt is like this:
line 1: blablabla......
line 2: blablabla......
line 3: blablabla......
......
line 100: blablabla......
To make this file, my matlab code is like this:
fprintf(file, 'line 1: blablabla...... \n');
fprintf(file, 'line 2: blablabla...... \n');
fprintf(file, 'line 3: blablabla...... \n');
......
fprintf(file, 'line 100: blablabla...... \n');
I just simply copy and paste every line in the txt file to every corresponding line of the 'fprintf' command. But txt file contains thousands of lines. It's too cumbersome to repeat the process of copy and paste again and again. So my question is ; Is there any way to make matlab read the txt file line by line and use a loop to generate 'fprintf' like this: fprintf(file, 'line 1: blablabla...... \n');
Accepted Answer
More Answers (0)
Categories
Find more on Low-Level File I/O in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!