Error using save. Unable to write file

I randomly got the error descripted in the title. Suddenly Matlab had errors using my field structure. I have a code like
In.C=c;
In.D=d;
Par.E=e;
Par.F=f;
In=orderfields(In);
save('filename.mat','In','Par')
Out.A=a;
Out.B=b;
Out=orderfields(Out);
save('filename.mat','-append','Out')
and I get an error for the last line here. I have a similar program that I didnt touch and worked perfectly fine before, just as this ine, now it gives the same error too.
I already tried saving in v7.3 and I also restarted Matlab and amso the PC, nothing worked.
If it helps, before that I had trouble with Parallel Computing Toolbox, which shutted down after each iteration and restarted again.
I also reinstalled Matlab, same problem. And inbetween I had also some trouble starting Matlab saying I dont have a valid license file, but then suddenly it worked again and I could run the code once or twice before the same error occured again. But I should have a valid license, Matlab profile doesnt say anything.
Does somebody know whats wrong?

7 Comments

Is that full error message you received? If not, then share the full error message i.e. all of the red text.
Does the error occur while saving any data or just this particular data only? If it occurs for this particular data only, please share the data so we can reproduce the error and provide suggestionsa accordingly.
It only says this Error:
Error using save
Unable to write file 'filepath\filename.mat'
Error in line n
save('filename.mat','-append','Out')
When I try to save a simple array it seems to work. When I run a different independent code in another folder which has a similar saving as descrpted above, the same error occurs.
But when I try to open the simple array I get this error:
Error using load
Unknown text on line number 1 of ASCII file
filepath\filename.mat
"MATLAB".
Error in uiimport/runImportdata (line 470)
datastruct = load('-ascii', fileAbsolutePath);
Error in uiimport/gatherFilePreviewData (line 438)
[datastruct, textDelimiter, headerLines]= runImportdata(fileAbsolutePath, type);
Error in uiimport (line 260)
gatherFilePreviewData(fileAbsolutePath);
Seems like a problem with that particular folder.
Does MATLAB have access to the folder for which the error occurs?
Try providing the full path to the file using dir and fullfile.
The same error occurs with a different but similar program stored in a completely different folder though :(
The thing is that it worked before without any problem and suddenly the same code gives this error. I didnt even close matlab between the time it worked flawlessly and now
Are you encountering this error within a parfor loop for just in regular serial code?
First it occured in a parfor loop, where the Parallel pool as stated before restarted for every iteration and gave the error after iteration three or so. Then I switched to for loop instead of parfor and there the same problem occured then. But the saving is after the loop.
I recommend against using uiimport() . uiimport() is guessing that your .mat file is a text file, and then is failing to load the binary .mat file as text.

Sign in to comment.

Answers (0)

Categories

Products

Release

R2023b

Asked:

on 27 Mar 2024

Commented:

on 27 Mar 2024

Community Treasure Hunt

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

Start Hunting!