Hey all,
An instance of a class is filled with a lot of data and than saved to my harddisk.
However, during saving, I get the following error: Error using save: Error closing file dummy.mat
I thought it had to do with a lack of memory, but I've monitored the process during saving and I never run out of RAM, and I know that I have plenty of space left on my harddisk.
Does anyone know what causes this error?
Any suggestions are much appreciated!

댓글 수: 1

Rafael Lopez Campos
Rafael Lopez Campos 2020년 12월 17일
Hi, I had the same problem. I was working my script in a external device, so I fixed it moving my environment in the same device Matlab is installed.

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

 채택된 답변

Jared
Jared 2011년 10월 18일

20 개 추천

Hi Bert,
I ran into the same error message a day or two ago with a struct filled with instances of classes that were similarly filled with lots of data. However, I could see in task manager that the memory use was in fact spiking.
The problem went away when I switched to version 7.3 format from version 7 (change file->preferences->general->MAT-Files or I think add flag '-v7.3' to save). This led me to believe that the memory problems might have had something to do with the form of compression done in mat files in version 7.
However, this does not solve another problem associated with save and load which might also cause some issues (it does for me). MATLAB uses lazy copying to conserve memory, i.e. A = B does not make a new copy of B until some part of A is later changed, e.g. perhaps A(end) = 1. Mat files appear to forget about all of these memory-saving relations, increasing both the size of the save files as well as the space required in memory once the save file is loaded.
Hope this helps! Jared

댓글 수: 16

Bert
Bert 2011년 10월 18일
Hey Jared,
Indeed this turned out to be the problem. I figured this out a while ago but forgot to report it to the community.
I think it would be a valuable addition in the error message as a suggestion ('Maybe add -v7.3?'), because the user is pretty much left in the dark about the reasons of this error message.
Jesse Salazar
Jesse Salazar 2015년 1월 17일
Also worked for me. No issues thus far with the lazy copying. Bert, do you anticipate issues with data integrity? Or simply with redundancy/memory? For my purposes, as long as there is no issue with data integrity, I should be okay. Thanks for your post,
-J
Colin
Colin 2016년 1월 27일
Great answer. I would have lost days without it! Thanks!
Céldor
Céldor 2016년 10월 4일
Thanks for this answer. I had the same error and adding '-v7.3' solved the problem. Before, I though the problem would be somewhere else as it suggests network or HDD problems.
I also believe adding more explanatory error would save everybody's time.
Scott Tuttle
Scott Tuttle 2017년 7월 11일
Many Thanks Jared! Using '-v7.3' on the save command fixed my case. I now made 7.3 the default in my preferences.
Rosalyn Putland
Rosalyn Putland 2018년 1월 17일
Thanks this fix worked perfectly!
Hans Kramer
Hans Kramer 2018년 9월 18일
Thanks man. Worked for me as well.
Manuel Lera Ramírez
Manuel Lera Ramírez 2019년 12월 4일
Hello Jared,
Thank you so much for your response. Allowed me to save some data it had taken me a while to analyse.
Mingli ZHU
Mingli ZHU 2021년 4월 23일
Tnanks, that helps
dain Yoon
dain Yoon 2021년 7월 29일
Thanks, that helps !!
Neil Arnold
Neil Arnold 2021년 8월 12일
Caveat emptor! I have generated a similar problem when trying to append to an existing file using the '-struct' option. In this case the '-v7.3' solution doesn't work. Moreover when I've attempted to load the existing data into memory, add the new data to the structure and save in v7.3 the process still fails. I have no working solution. I've resorted to the brute force solution of saving separate files (as v7 BTW)..
Tiago Ávila
Tiago Ávila 2021년 12월 10일
This also works on Ubuntu 21.04 with big files! Was hoping the command window would hint at this since it's a common issue.
Berkin Birol
Berkin Birol 2022년 1월 28일
편집: Berkin Birol 2022년 1월 28일
Thank you Jared for the answer, it saved me from a lot of work.
And thank you Bert for asking the question :)
baby
baby 2022년 8월 19일
편집: baby 2022년 8월 19일
Thanks a bunch. Solved my problem too by -v7.3. Spent days to take tries with different options for nothing.
Alejandro
Alejandro 2023년 2월 13일
Thanks a lot! This was extremely useful! Solved the same problem by using this method!
Ankit Nag
Ankit Nag 2023년 6월 22일
Is there any way to use -v7.3 and yet keep the file size reasonable. I am saving figures plotted from a large data set and faced this issue. I was able to solve it using v7.3 but I am trying to keep them at a manageable file size. Using -v7.3 seems to be doubling the figure's file size.

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

추가 답변 (2개)

Jonathan Pelham
Jonathan Pelham 2015년 2월 17일

0 개 추천

I have had a similar error message. This is a very old q&a. Does anyone know if the answer is still valid?

댓글 수: 1

Ingo Schalk-Schupp
Ingo Schalk-Schupp 2015년 7월 21일
For me, this also did the trick. I was saving using the -v6 switch, and I got the error reproducibly. After I removed it, the error did not occur any longer.

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

Zaki Mohzani
Zaki Mohzani 2016년 9월 7일

0 개 추천

Ran into this error today. That error message should be updated to reflect the new 'v7.3' option.

댓글 수: 3

Henrique Costa
Henrique Costa 2017년 5월 5일
Now it is: save('myFile.mat','-v7.3','-nocompression');
Henrique Costa
Henrique Costa 2017년 5월 5일
or, if you want compression : save('myFile.mat','-v7.3');
Adam Bruce
Adam Bruce 2020년 11월 18일
편집: Adam Bruce 2020년 11월 18일
This still works on 2020a. Thanks!

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

카테고리

도움말 센터File Exchange에서 Historical Contests에 대해 자세히 알아보기

제품

질문:

2011년 10월 12일

댓글:

2023년 6월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by