I seem to have found a workaround by creating a function in a separate .m in the same folder that calls mfilename("fullpath"), and Matlab is smart enough to give the directory of that function rather than the live editor temporary file location.
Separate .m file get_current_dir.m :
function current_dir = get_current_dir()
current_dir = fileparts(mfilename("fullpath"));
end
Then if I do:
a = mfilename('fullpath')
b = get_current_dir()
a = 'C:\Users\MyName\AppData\Local\Temp\Editor_mddon\LiveEditorEvaluationHelperE847216552'
b =
'C:\MatlabFolder'
It's a shame to need a separate .m file to do something fundamental that should be built-in, and I try to trail around the feasible minimum number of files, but it's certainly doable if this is a robust solution. Any pitfalls of this method I should be aware of? Thanks.