How can I save a variable as -v7 by default and switch to -v7.3 only if the variable is too large using SAVE on 64-bit MATLAB 7.12 (R2011a)?

조회 수: 3 (최근 30일)
I have a script where I am writing variables in the workspace to MAT-files using the following syntax:
X = zeros(100,1);
save('test.mat', '-v7', 'X')
I prefer the -v7 option because the files are smaller and the SAVE command is quicker. However, if I try to save a file that is too large for -v7, I want to be able to switch to -v7.3 automatically. How can I do this?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2020년 4월 7일
편집: MathWorks Support Team 2020년 4월 7일
You can test for the warning that occurs when you attempt to save a very large variable into a -v7 MAT-file. Here is an example:
X = zeros(30000, 10000); % create a large matrix that is too large to be saved as -v7
lastwarn('') % This will clear any last warnings so there is no confusion
save('test.mat', '-v7', 'X'); % attempt to save the file in -v7 format
[msg,id]=lastwarn('') % This will save the last warning
if strcmp(id,'MATLAB:save:sizeTooBigForMATFile') % compare the id of the warning with the one we are looking for
save('test.mat','-v7.3','X'); % save the variable in a -v7.3 MAT-file
end

추가 답변 (0개)

카테고리

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

제품


릴리스

R2011a

Community Treasure Hunt

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

Start Hunting!

Translated by