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일

4 개 추천

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

댓글 수: 4

lowcalorie
lowcalorie 2012년 3월 15일
this overwrote my data it did not add data to the data already there
Walter Roberson
Walter Roberson 2012년 3월 15일
Change the 'a+' to 'at'
And while you are at it, switch to a more modern text editor ;-)
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일

8 개 추천

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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by