Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does MATLAB save() call saveobj() twice?

Tags:

save

matlab

I define a MATLAB object class_save_test:

classdef class_save_test 
    methods
        function b=saveobj(a)
            fprintf('saveobj called.\n');
            b=a;
        end
    end
end

When I try to save it:

j=class_save_test
save('delme1.mat','j')

I get the output

saveobj called.
saveobj called.

Why is it called twice? I have found this and this where people had the same question, but no answer :-(. I'm using Matlab 7.11.0 (R2010b).

Update: I have filed a support request with Mathworks... find their answer below :-).

like image 335
Jonas Heidelberg Avatar asked Jul 13 '11 10:07

Jonas Heidelberg


1 Answers

According to MathWorks Technical Support:

Our current save (pre-HDF5) MAT implementation requires us to compute the size of the data on disk before actually saving the data and this cause us to go through the save process twice. This doesn't happen with HDF5 format. So doing save('delme1.mat','j','-v7.3') will display the message only once.

I have changed my preferences (File/Preferences/General/MAT-Files) to "MATLAB Version 7.3 or later", so now save('keepme.mat','j') works for me :-).

like image 72
Jonas Heidelberg Avatar answered Sep 20 '22 06:09

Jonas Heidelberg