saving data to the file

How to use function fprintf in Matlab2016b? Why thoe following comands are uncorrect?
fid = fopen('file.txt','a');
fprintf(fid,'%.6f %.6f %.6f\n',xw,yw,rw);
fclose(fid);

댓글 수: 4

KSSV
KSSV 2016년 10월 10일
fid = fopen('file.txt','a');
xw = rand(1) ;
yw = rand(1) ;
rw = rand(1) ;
fprintf(fid,'%.6f %.6f %.6f\n',xw,yw,rw);
fclose(fid);
works very fine....what error it pop's out for you?
José-Luis
José-Luis 2016년 10월 10일
What's the error message you are getting?
Artur Lipnicki
Artur Lipnicki 2016년 10월 10일
Error using fprintf Invalid file identifier. Use fopen to generate a valid file identifier.
José-Luis
José-Luis 2016년 10월 10일
What's the value of fid?
Do you have write access to the current folder?

답변 (2개)

Pritesh Shah
Pritesh Shah 2016년 10월 10일

0 개 추천

Did you defined the variable xw,yw,rw?
Guillaume
Guillaume 2016년 10월 10일

0 개 추천

Matlab failed to open the file. There may be many reasons for this, the file does not exist / the file is not is in the current directory (since you didn't specify a path) / you don't have read access to the file / something else.
Open the file with
[fid, errmsg] = fopen('file.txt', 'a');
assert(fid > 0, 'Failed to open file because: %s', errmsg);
And see what error you get.

이 질문은 마감되었습니다.

질문:

2016년 10월 10일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by