Writing text file

If i have a variable, say time=1000, and i want to write this into a txt file, how do i do that?
this is what i have tried:
fid = fopen('exp.txt', 'w');
fprintf(fid, 'time');
fclose(fid);
thanks

 Accepted Answer

fid = fopen('exp.txt', 'w');
fprintf(fid, '%g\n', time);
fclose(fid);

2 Comments

Andy
Andy on 16 Jan 2012
hi, thanks for the response, but i tried it, it doesnt save anything.
Works fine for me.
>> time = 1000
time =
1000
>> fid = fopen('exp.txt', 'w');
fprintf(fid, '%g\n', time);
fclose(fid);
>> !cat exp.txt
1000

Sign in to comment.

More Answers (1)

sunil anandatheertha
sunil anandatheertha on 17 Jan 2012

0 votes

ahhhhhhh, i use the dlmwrite('D:\rrr.txt','delimiter','\t') instead.
Whichever works for the moment !! ;)

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!