Error in save to mat file

조회 수: 101 (최근 30일)
Praveen Kumar Nambisan T M
Praveen Kumar Nambisan T M 2021년 6월 18일
댓글: Abhishek 2025년 2월 19일
I have got following error while saving the agent for a DQN-RL problem. The error doesnt pop-up always, however, most of the time the saved .mat file is corrupt Similar problem in another PC too. Both the PC is having enough space in the HDD and of 64GB RAM. Sometimes it saves successfully with each MAT file of 1GB size,otherwise, the corrupted MAT files are in KBs.
Version: MATLAB 2021a
Error:
Error using save
Unable to save file 'C:\Users\Documents\MATLAB 2021\initial_agent.mat'. The file could not be closed, and might now be corrupt.
Error in DQN__Training (line 101)
save("initial_agent","agent")
  댓글 수: 4
Praveen Kumar Nambisan T M
Praveen Kumar Nambisan T M 2022년 2월 11일
Thanks for the answer. It might be due to network file system as there was no limitations in the disk space.
However, I have reinstalled the MATLAB and it solved the issue.
Sebastian Theilenberg
Sebastian Theilenberg 2023년 9월 5일
For future reference, because the error message doesn't really point towards this:
I had the same error in Matlab 2022b both on the local SSD and when saving to a network storage. I was able to fix it using version '-v7.3'.
I'm not sure why this fixed the issue (e.g., the file size was only about 240 MB), but it's worth a try.

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

답변 (1개)

Kautuk Raj
Kautuk Raj 2024년 9월 11일
It seems like the issue you are encountering with saving the agent for your DQN-RL problem might be related to the MAT-file version being used. By default, MATLAB saves files in version 7.0, which has limitations on the size of variables it can store. This could explain why your large files are sometimes corrupt, especially when they exceed the capacity of version 7.0.
To resolve this issue, you can save your MAT-files in version 7.3, which supports larger file sizes. Here is how you can do it:
(1) Change Default Save Settings:
Go to Preferences > MATLAB > General > MAT-Files.
Select MATLAB Version 7.3 or later (save -v7.3).
(2) Specify Version 7.3 When Saving:
Use the -v7.3 flag with the ‘save function:
save('initial_agent', 'agent', '-v7.3');
(3) Further, if you have an existing version 7.0 MAT-file and need to append large data, you can convert it to version 7.3 first:
load('existing_file.mat');
save('existing_file.mat', '-v7.3');
save('existing_file.mat', 'largeVariable', '-append');
For more detailed information, you can refer to the MATLAB documentation on MAT-file versions (https://www.mathworks.com/help/releases/R2021a/matlab/import_export/mat-file-versions.html) and saving data (https://www.mathworks.com/help/releases/R2021a/matlab/ref/save.html).
  댓글 수: 2
Narendran M
Narendran M 2024년 12월 5일
Thankyou, this helped me resolve a similar issue.
Abhishek
Abhishek 2025년 2월 19일
Thank you, this resolved the issue.

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

카테고리

Help CenterFile Exchange에서 Install Products에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by