slash / after text .txt

조회 수: 3 (최근 30일)
Vadim Tambovtsev
Vadim Tambovtsev 2016년 9월 29일
댓글: Massimo Zanetti 2016년 9월 29일
% open your file for writing
fid = fopen('test.txt','wt');
fprintf(fid,'super\n')
% write the matrix
myData = randi(255,10,3);
if fid > 0
fprintf(fid,'%d %d %d\n',myData');
fclose(fid);
end
This script creates a .txt file of the following format: super, then 10x3 array
The question: how to add "/" after(down) the array? Thank you!

채택된 답변

Massimo Zanetti
Massimo Zanetti 2016년 9월 29일
Just print it before closing the file.
% open your file for writing
fid = fopen('test.txt','wt');
fprintf(fid,'super\n');
% write the matrix
myData = randi(255,10,3);
if fid > 0
fprintf(fid,'%d %d %d\n',myData');
end
fprintf(fid,'/');
fclose(fid);
  댓글 수: 2
Vadim Tambovtsev
Vadim Tambovtsev 2016년 9월 29일
Error using fprintf Invalid file identifier. Use fopen to generate a valid file identifier.
Error in test2 (line 10) fprintf(fid,'/');
Massimo Zanetti
Massimo Zanetti 2016년 9월 29일
This error does not relate to "/". You are not properly opening the txt file. Indeed, I run it and it works, look in the file attached.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Standard File Formats에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by