How to modify a txt file

1 view (last 30 days)
Juan Vaca
Juan Vaca on 26 Aug 2015
Answered: Walter Roberson on 26 Aug 2015
Good morning I have the following info in a .txt file:
*AREA
26080, 26081, 26082, 26083, 26084, 26085, 26086, 26087, 26088, 26089,
26090
And I need to read this file and modify it into the next .txt file like this:
*AREA
26080,
26081,
26082,
26083,
26084,
26085,
26087,
26088,
26089,
26090
How can I do this?
I apprecciate a collaboration
  1 Comment
James Orr
James Orr on 26 Aug 2015
Might be simpler to write a simple c program to do this, and call that c program from within your matlab program.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 26 Aug 2015
fidin = fopen('ExistingFile.txt', 'rt');
fidout = fopen('NewFile.txt', 'wt');
header = fgets(fidin);
fwrite(fidout, header);
datacell = textscan(fidin, '%f');
fclose(fidin);
fprintf(fidout, ' %g,\n', datacell{1}(1:end-1));
fprintf(fidout, ' %g\n', datacell{1}(end));
fclose(fidout);

Community Treasure Hunt

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

Start Hunting!