how can ı solve this error ? Error using fprintf Invalid file identifier. Use fopen to generate a valid file identifier.

5 ビュー (過去 30 日間)
clear all;clc;
y=[2 3 4 5;5 6 7 8]
fid=fopen('myfile.txt','wt');
fprintf(fid,'%d,%d\n',y);
fclose(fid);

採用された回答

Jan
Jan 2015 年 5 月 31 日
Check the success of fopen in every case, under all circumstances, ever, nerver omit this test:
filename = 'myfile.txt';
filepath = cd;
file = fullfile(filepath, filename);
fid = fopen(file, 'wt');
if fid==-1
error('Cannot open file for writing: %s', file);
end
I guess you do not have privileges to write to the current folder.
  4 件のコメント
Yu-Ming Chen
Yu-Ming Chen 2017 年 6 月 19 日
Thank you Jan Simon. You saved me.
Stephen23
Stephen23 2017 年 6 月 19 日
編集済み: Stephen23 2017 年 6 月 19 日
Even better is to get the very informative message returned by fopen:
[fid,msg] = fopen(file, 'wt');
assert(fid>=3,msg)

サインインしてコメントする。

その他の回答 (2 件)

Caio Vaz Rimoli
Caio Vaz Rimoli 2018 年 9 月 4 日
Just brief comment: I also got this error because I ran out HD memory.

Aparna Komarla
Aparna Komarla 2018 年 10 月 2 日
Creating the directory you are storing the files/data in first might help!

カテゴリ

Help Center および File ExchangeTroubleshooting in MATLAB Compiler SDK についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by