Save .mat "Unable to write file"

I'm trying to write some worskpace variables with the command:
save('Z:\dir1\dir2\filename.mat','var1','var2','var3','var4','var5');
Where Z: is a windows (SMB) network drive. I get the following error when I try the command:
Error using save
Unable to write file
'Z:\dir1\dir2\filename.mat'
I have written many .mat files before in Z: without issues. In particular 'var1' is a relatively big variable, a 2605056x91 single array. When leaving out 'var1' the writing works, and trying to write only 'var1' also fails, so it seems to be a problem related only with 'var1'. I have write permissions since writing to the same location works with smaller size variables.
I also have tried writing the same variables (including 'var1'), with the same file name, to a different (SMB) network drive and the save works correcly. So the problem is only in the Z: drive, with 'var1'. Have anyone had a similar problem, or have any idea what could be the problem?
BTW, I also tried 'fwrite' of a large size binary file (larger size than the correctly saved '.mat' in the other network drive) to the same location in Z:, and it works correcly.
If it helps, the output of the try catch "getReport" when the save throws the error message is:
Error using <a href="matlab:matlab.lang.internal.introspective.errorDocCallback('save')"
style="font-weight:bold">save</a>Unable to write file'Z:\dir1\dir2\filename.mat'.
And the MException identifier is
"MATLAB:save:cantWriteFile"
Thank you.

답변 (1개)

Matthew Moschella
Matthew Moschella 2025년 12월 8일

0 개 추천

For the scenario when you attempt to save 'var1', have you tried changing the 'version' flag of the save function to '-v7.3'?
In your case: save('Z:\dir1\dir2\filename.mat','var1','var2','var3','var4','var5','v7.3');

댓글 수: 4

Small correction: it would be
save('Z:\dir1\dir2\filename.mat','var1','var2','var3','var4','var5','-v7.3');
Using -v7.3 is certainly what I would try in this situation. That said,
2605056*91*8 is less than 2^31 so the variable should fit in a -v7 file even if the variable is double precision instead of single precision. (It is not immediately clear what "single array" means in this context.)
Alan Miranda
Alan Miranda 2025년 12월 9일
Yes, I also tried with the flag '-v7.3' and still the error appers. Also with the '-nocompression' the error appears. Yes I mean single precission array, so indeed it should work with the basic "save" command.
Walter Roberson
Walter Roberson 2025년 12월 9일
Is it possible that you are running out of disk space on z: ?
Alan Miranda
Alan Miranda 2025년 12월 9일
No, I do have several GB of additional space than needed

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

릴리스

R2024a

태그

질문:

2025년 12월 8일

댓글:

2025년 12월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by