I am facing an error "invalid file identifier" while using fprintf and fopen
1 回表示 (過去 30 日間)
古いコメントを表示
in my script i am trying to store my result variable using the following line of code,
if(ledaOrLocal ==0)
sdir = 'F:/MS Thesis/Data/Dataset/';
resultDir = 'F:/MS Thesis/Data/Results/';
outputFileName = [resultDir, 'ResultsForParameterTrainingV1To_', num2str(kernel_param.idataset), '.txt'];
file_1 = fopen(outputFileName,'w');
for version = myStart:totalVersions
disp('-------------------------------------------------');
fprintf(file_1,'\n');
fclose(file_1);
but facing the issue of "invalide identifier, the error snap is attached, how it could be solved, help is highly appreciated. thanks
0 件のコメント
回答 (1 件)
Jan
2023 年 1 月 11 日
Whenever you try to open a file, check the success:
[file_1, msg] = fopen(outputFileName, 'w');
assert(file_1 > 0, msg);
Now you see an error message, if the file cannot be opened.
Maybe the directory is not existing or you do not have write permissions in this folder.
Use fullfile instead of concatenating the char arrays:
outputFileName = [resultDir, 'ResultsForParameterTrainingV1To_', num2str(kernel_param.idataset), '.txt'];
% Or safer:
outputFileName = fullfile(resultDir, sprintf('ResultsForParameterTrainingV1To_%d.txt', kernel_param.idataset));
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Install Products についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!