how can i open and add text to a .txt file?

Hello,
I have this List.txt file:
id firstname_lastname department first second third
3033011 Penelope_Cruz Cnm 99 88 77
404402 Gary_Cooper Bio 45 45 45
5055022 Tony_Curtis Dis 23 89 100
606603 Jim_Carrey Mng 100 100 100
I need to open it with matlab and then I need to add this:
12131415 Jack_Nicholson Mat 60 70 80
to List.txt
How can I do this?
also, I can only get the name Jack Nicholson without the underscore.
Thanks

 Accepted Answer

fid = fopen(filename, 'at');
if fid ~= -1
fprintf(fid, ...... whatever.....
fclose(fid);
end

6 Comments

I dont understand what I need to write in the whatever part
Whatever part is whatever you want to write to the file! lol
Replace it with your data, for instance
data = '12131415 Jack_Nicholson Mat 60 70 80'
fid = fopen('List.txt', 'at');
fprintf(fid, '%s\n', '12131415 Jack_Nicholson Mat 60 70 80');
fclose(fid);
the problem in that I cant enter this whole line together " 12131415 Jack_Nicholson Mat 60 70 80" I can get it that way: id=12131415; name=Jack_Nicholson; department=Mat; first=60; second=70; third=80;
Then do
fprintf(fid, '%d %s %s %d %d %d\n', id, name, department, first, second, third);

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!