Why can't my function write to a file when executed in parallel? (parfeval)
显示 更早的评论
"timestamp.m" doesn't work as expected when running in parallel.
1.file_path = 'C:\Users\user\Downloads\filename.txt'
ファイルパスが上記の時は正常に動作します。
It works fine.
2.file_path = 'C:\filename.txt'
ファイルパスが上記の時はファイルは作成されませんし、エラーもでません。
No files are created and no errors occur.
訂正:エラーはでていました。
K>> f.Error
ans =
ParallelException のプロパティ:
identifier: 'MATLAB:FileIO:InvalidFid'
message: 'ファイルの識別子が無効です。有効なファイルの識別子を生成するには fopen を使用してください。'
cause: {}
remotecause: {[1×1 MException]}
stack: [1×1 struct]
Correction: []
function functionname
...
f = parfeval(@timestamp,0)
...
end
timestamp.m
function timestamp
stat = true;
while(stat==true)
dt = datetime('now');
fileID = fopen(file_path,'a');
fprintf(fileID,'%s\n',datestr(dt));
fclose(fileID);
pause(5)
end
end
2 个评论
Kojiro Saito
2022-5-31
2.のときのparfevalの出力はどうなっていますか?
f = parfeval(@timestamp,0);
として、f.Errorにメッセージが書かれていないでしょうか?
Takafumi Shiino
2022-6-1
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!