Problem with fscanf.
8 ビュー (過去 30 日間)
古いコメントを表示
Hello. I haven't written the script, but I used it before. Now it texts out three errors:
"Error using fscanf
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in diagram_type (line 459)
optiondata=fscanf(optionfile, '%c'); % read file
Error in PARALYZER (line 281)
minu1,minu1text,maxu2,maxu2text,minu2,minu2text] = diagram_type(project_name);"
There is a code of the script attached... HELP ME, PLEASE !
2 件のコメント
回答 (1 件)
Walter Roberson
2017 年 10 月 14 日
The code looks in the file content for the phrase "computational option file", and if it finds the phrase, it extracts a file name. If it does not find that phrase, then it uses the name perplex_option.dat instead. Then it attempts to open that file, and it does not check first to be sure it exists, and it does not give a nice message about why it could not open the file.
I recommend improving the code, changing
optionfile=fopen(option_file); % choose & open file
optiondata=fscanf(optionfile, '%c'); % read file
perline_option_file=textscan(optiondata,'%s',...
'delimiter','\n','whitespace',''); % scan per line
perline_option_file=perline_option_file{1}; % take just first dimension
length_options=length(perline_option_file);
for line=1:length_options % loop to read value of auto_refine option (a, m, or o [aut, man, o])
content = num2str(perline_option_file{line});
if strcmp(content(1:12),'auto_refine ')==1
for i=12:length(content) % find position of firstnon-space
if content(1,i)~=' '
auto_refine=content(i); % read character at this position
break
end
end
end
end
fclose(optionfile); % close file
to
auto_refine = 'a'; %default to auto if we do not find option file
[optionfile, msg] = fopen(option_file); % choose & open file
if optionfile < 0
fprintf('skipping unreadable option file "%s", problem was: "%s"', option_file, msg);
else
optiondata=fscanf(optionfile, '%c'); % read file
perline_option_file=textscan(optiondata,'%s',...
'delimiter','\n','whitespace',''); % scan per line
perline_option_file=perline_option_file{1}; % take just first dimension
length_options=length(perline_option_file);
for line=1:length_options % loop to read value of auto_refine option (a, m, or o [aut, man, o])
content = num2str(perline_option_file{line});
if strcmp(content(1:12),'auto_refine ')==1
for i=12:length(content) % find position of firstnon-space
if content(1,i)~=' '
auto_refine=content(i); % read character at this position
break
end
end
end
end
fclose(optionfile); % close file
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Shifting and Sorting Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!