Hi! Could somebody tell me why few days ago this code worked and now I tried it again and gives me this error? Thank you!

1 ビュー (過去 30 日間)
gblmtc
gblmtc 2017 年 12 月 9 日
コメント済み: gblmtc 2017 年 12 月 9 日
fmt=['PG10 ' repmat('%f ',1,8)];
fid=fopen('sp3data.txt');
PG10=[];
while ~feof(fid)
l=fgetl(fid); % read a record
if strfind(l,'PG10')
PG10=[PG10; cell2mat(textscan(l,fmt,'collectoutput',1))];
end
end
fclose(fid);
Error using feof
Invalid file identifier. Use fopen to generate a valid file identifier.

回答 (1 件)

Stephen
Stephen 2017 年 12 月 9 日
編集済み: Stephen 2017 年 12 月 9 日
Replace the fopen line with this:
[fid,msg] = fopen('sp3data.txt');
assert(fid>=3,msg)
And then read the displayed message. Most likely fopen cannot open the file because there is no such file in the specified location.

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by