appending a file

219 次查看(过去 30 天)
lowcalorie
lowcalorie 2012-3-15
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

采纳的回答

Walter Roberson
Walter Roberson 2012-3-15
fid = fopen('hello.txt', 'a+');
fprintf(fid, '%d %d %d\n', v);
fclose(fid);
  4 个评论
Walter Roberson
Walter Roberson 2012-3-15
See, Jan, people do still use WordPad and still need the 't' permissions ;-)
Walter Roberson
Walter Roberson 2012-3-15
>> !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

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2012-3-15
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 个评论
Wayne King
Wayne King 2012-3-15
I second Walter's sentiment. People are volunteering their time to help you.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Text Data Preparation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by