How to write vectors line by line in a txt file using fprintf delimited by a space?

조회 수: 8 (최근 30일)
I have for example these three vectors : [1 2 3 ], [4 5 6 ],[7 8 9]. I would like to get the result like this in the file txt:
1 2 3 4 5 6 7 8 9
(each vector in a line) I tryed this
fid= fopen('h.txt','w');
fprintf(fid,'%.5f',h0);
fclose(fid)
but i didn't get the result. Delimiter ' ' doesn't work with this command.

채택된 답변

Adam
Adam 2015년 8월 6일
fprintf(fid,'%.5f ',h0);
should be enough. Note the space in the string.
  댓글 수: 2
bh dhouha
bh dhouha 2015년 8월 6일
So i don't have to open and close the file everytime i add a vector to the file ? because in my program i have a for loop, in every iteration i add a vector to the file.
Stephen23
Stephen23 2015년 8월 6일
편집: Stephen23 2015년 8월 6일
You can open the file once before the loop, and close it after the loop.

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

추가 답변 (0개)

카테고리

Help CenterFile 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