saving variable with -v7.3 flag check

8 次查看(过去 30 天)
Hi i have a code in which i have a an array with 4 field called Data
Data.name Data.index Data.PixelInd Data.bbox
I save it in the end but for some images this variable Data become large and matlab does not allow to save it as a mat File unless you turn on the v-7.3 switch.So i want to have a check in my code that if the variable is bigger than this size then save it with -v7.3 flag else save it using without this flag.
if(Data is greater than 2Gb)
save(fileName.mat, 'Data' ,'-v7.3')
else
save(fileName.mat, 'Data')
end
Thanks anyways

采纳的回答

Philip Borghesani
Philip Borghesani 2015-1-13
编辑:Philip Borghesani 2015-1-13
Use the whos function:
varinfo=whos('data');
saveopt='';
if varinfo.bytes >= 2^31
saveopt='-v7.3';
end
save('filename','data',saveopt);
This code is a bit too conservative in that it will use -v7.3 format when data is over 2gb but only needs to when a member of data is over 2gb. I do not see that as a problem and checking all members is a bit more work.
That said I would not do this. I would use the -v7.3 option for all files. Some day in the future it may complicate things to have files that are of different formats.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by