Error using save Unable to write file datafiles/f01.mat: No such file or directory.

keep getting this error for simple save function. heres my code
if (jrandflag == 1) o = jrand.createShiftVector(D, lb, ub); o = o'; save('datafiles/f01.mat', 'o'); else load('datafiles/f01.mat'); o = o(1:D); end
datafiles folder does exist in same directory; expect'd save function to create f01.mat but error every time. and code not in loop per se
Can anyone help please? Thanks
Matlab version 7.10.0.499 (R2010a) on windows platform

 Akzeptierte Antwort

'datafiles/f01.mat' isn't the full path of the file, is it? If you mean to save it in the current folder, try.
save(fullfile(pwd,'datafiles/f01.mat'));

Weitere Antworten (1)

Bart Van Hove
Bart Van Hove am 12 Jan. 2018
When my MATLAB (2014b) has been running for a while (days), sometimes the current folder disappears from the path (have not verified if this is exactly what happens). Running scripts, functions, loading files... continues to work, but saving to subdir/file.mat does not. Moving up 1 directory in the MATLAB file browser and re-entering the current folder resolves the issue for me. Saving with a full path as suggested by Jiang avoids this issue, but I'm still curious why it occurs.

2 Kommentare

I experienced the same issue with R2014b, and the workaround is the same. I'm curious if they fixed it on next versions.
I can confidently say that in 2023, with version R2023a, this is still a problem!

Melden Sie sich an, um zu kommentieren.

Kategorien

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by