필터 지우기
필터 지우기

Unable to save variables and figures of large arrays

조회 수: 18 (최근 30일)
Kobi
Kobi 2018년 11월 13일
답변: Philipp Lauff 2024년 6월 30일 21:24
i keep getting this error:
Warning: Variable 'hgS_070000' cannot be saved to a MAT-file whose version is older than 7.3.
To save this variable, use the -v7.3 switch.
Skipping...
> In matlab.graphics.internal.figfile.FigFile/write (line 32)
In savefig (line 84)
Error using save
Error closing file D:\Dropbox (Personal)\C\Resaults\2018_11_13_21_45_10.926(Temperature map).fig.
Error in matlab.graphics.internal.figfile.FigFile/write (line 32)
save(obj.Path, obj.MatVersion, '-struct', 'SaveVars');
Error in savefig (line 84)
FF.write();
i use this command
savefig([time_stamp,'(LASER)','.fig'])
saveas(gcf,[time_stamp,'(LASER)','.png'])
the arrays are really big 15000x30000
what is the meaning of this error?
how to avoid it?

채택된 답변

Stephen23
Stephen23 2018년 11월 14일
편집: Stephen23 2018년 11월 14일
"what is the meaning of this error?"
The .fig file format is really just a .mat that stores all of the objects in a figure. Most of the time this happens quite seamlessly, so the user never notices or cares how .fig files are saved. But .mat files are not all the same: in particular, the size of arrays that can be saved has increased significantly as MATLAB has developed. You can see these differences summarized here:
What appears to have happened is that whoever wrote the .fig saving code did not consider that someone might want to save a figure with such a huge amount of data, and the size is beyond the specification for the default .mat file version that the .fig saving code uses (here in bytes):
>> 2^31
ans = 2147483648
>> 15000*30000*8
ans = 3600000000
"how to avoid it?"
You might like to try using saveas, to see if it handles this better.
Otherwise I doubt that there is a simple solution, but I think you should definitely report this as a bug.
  댓글 수: 6
Marc Compere
Marc Compere 2020년 4월 1일
편집: Marc Compere 2020년 4월 1일
I have this same issue on Ubuntu 18 Linux in R2019a.
The savefig command it's still failing with a simple file: /tmp/tmp.fig:
>> saveStr = '/tmp/tmp.fig';
>> savefig(h,saveStr,'compact')
Error using save
Error closing file /tmp/tmp.fig.
The file may be corrupt.
Error in matlab.graphics.internal.figfile.FigFile/write (line 32)
save(obj.Path, obj.MatVersion, '-struct', 'SaveVars');
Error in savefig (line 83)
FF.write();
>>
This appears to be a bug. The other figures of similar complexity generate .fig files less than 0.5Mb. The figures have lots of data but the resulting .fig files are not large for those that work.
Matlab has a resident memory footprint of 12Gb on a machine with plenty of more ram than that. The problem is not lack of physical memory but still this file writing process fails.
The failuse occurrs with and without the 'compact' designator.
Writing to .png files works fine. It's the .fig file format that is the problem.
Any solutions????
Marc Compere
Marc Compere 2020년 4월 1일
This is the png export of a figure that fails when attempting to write the .fig file. It has subplots and a fair amount of data but it's not unreasonable:

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

추가 답변 (1개)

Philipp Lauff
Philipp Lauff 2024년 6월 30일 21:24
Hi, I still encounter this problems (5 yeras later...) and I just took a look into the code. To fix it, follow these steps.
Copy from
"C:\Program Files\MATLAB\R2023b\toolbox\matlab\graphics\objectsystem\"
the file savefig.m and folder \private\ to your current working directory.
In the copied savefig.m add "FF.MatVersion = '-v7.3';" before the "FF.write();" (currently line 83). Now Matlab prefers your version of the savefig function and will use your code with the MAT-File version 7.3.
This is not the prettiest workaround as you have to copy the adjusted file and the folder to all your working directories (if you have mutliple), but changing it in the Matlab folder won't do the trick. I suppose, these files are precompiled and therefore changes are not executed.

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by