function [org_data] = file_manipulation(in_fname, txt_fname, mat_fname)
org_data = round(load(in_fname));
fid = fopen(txt_fname,'wt+');
student_id = '9900';
txt = [txt_fname ' : ' student_id '\nDate of creation:' datestr(now,'dd/mm/yyyy')];
fprintf(fid,'%s',txt);
end
Instead of inserting a newline the file generated is:
C:\w2\test1.txt : 9900\nDate of creation:30/05/2012
What's the problen with my code?
Use sprintf
to make those strings:
fprintf(fid, sprintf('%s : %s\nDate of creation: %s', txt_fname, student_id, datestr(now,'dd/mm/yyyy')));
The way you're doing it now, it treats the backslash as a literal.
Convert the '\n' to double before you insert it to the string:
fid = fopen('my_file.txt', 'w');
fwrite(fid, ['First line' double(sprintf('\n')) 'Second line'])
fclose(fid);
Thanks to Franck Dernoncourt, Reseach Scientist at Adobe Research.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With