MATLAB Answers

0

appending a file

Asked by lowcalorie on 15 Mar 2012
i have a file called hello.txt using wordpad which contains the matrix
2 7 3
2 6 9
now i have a vector v = [1 2 3] and i want to add this vector to the hello.txt file so when i open the hello.txt file i should have
2 7 3
2 6 9
1 2 3
how can i do this

  0 Comments

Sign in to comment.

2 Answers

Walter Roberson
Answer by Walter Roberson
on 15 Mar 2012
 Accepted Answer

fid = fopen('hello.txt', 'a+');
fprintf(fid, '%d %d %d\n', v);
fclose(fid);

  4 Comments

Show 1 older comment
Walter Roberson
on 15 Mar 2012
Change the 'a+' to 'at'
And while you are at it, switch to a more modern text editor ;-)
Walter Roberson
on 15 Mar 2012
See, Jan, people do still use WordPad and still need the 't' permissions ;-)
Walter Roberson
on 15 Mar 2012
>> !cat hello.txt
2 7 3
2 6 9
>> fid = fopen('hello.txt','at')
fid =
3
>> v = [1 2 3]
v =
1 2 3
>> fprintf(fid, '%d %d %d\n', v);
fclose(fid);
>> !cat hello.txt
2 7 3
2 6 9
1 2 3

Sign in to comment.


Walter Roberson
Answer by Walter Roberson
on 15 Mar 2012

Your existing question is still here and still active. Please do not open duplicate questions: it just leads to frustration and confusion.
If you require answers within 10 minutes (as implied by the time between your reply here and the time you opened the duplicate question), then you should be hiring a consultant.

  1 Comment

Wayne King
on 15 Mar 2012
I second Walter's sentiment. People are volunteering their time to help you.

Sign in to comment.