matlabFunction randomly throws errors

5 ビュー (過去 30 日間)
Jurriën
Jurriën 2018 年 4 月 16 日
回答済み: Jurriën 2018 年 4 月 24 日
As a replacement for global variables, I use matlabFunction to write numbers and variables to a function, which I then access as if it were a global variable. However, matlabFunction is not very reliable. At random moments it will fail and throw the following error:
Error using sym/matlabFunction>writeMATLAB (line 431)
Failed to create file TEST.m: Invalid argument.
Error in sym/matlabFunction (line 179)
g = writeMATLAB(funs,file,varnames,outputs,body, opts.Optimize, opts.Sparse);
I created this simple code to reproduce the problem:
for i=1:100
try
matlabFunction(sym(5),'File','TEST');
catch
disp(i)
end
end
For me this code generally displays 3 or 4 random numbers between 1 and 100, indicating 3 or 4 errors in running 100 iterations of the exact same code. Some days it may be less and I might require 1000 iterations to produce 4 errors.
As a workaround, I simply try to call the function again:
for i=1:10
try
matlabFunction(sym(0),'File','get_xf');
break
catch
disp('matlabFunction error')
continue
end
end
In theory, this workaround is not 100% safe. In practice, however, it suffices.
The question is, what is causing these errors and how do I prevent them? Not sure if it's relevant, but I use version R2017a under an academic license.
Kindest regards,
Jurriën

採用された回答

Jurriën
Jurriën 2018 年 4 月 24 日
I contacted Mathworks support and they suggested a number of reasons that might cause this kind of error. It turns out it was caused by Dropbox. I run my script in a folder that is synced, and this syncing may prevent Matlab from writing a function and thus throw an error.
So for anyone reading this and having the same issue: don't save your scripts in a synced folder.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by