Serialize or save and reload large scatteredInterpolant objects
5 views (last 30 days)
Show older comments
Hi guys,
I'm running into following problem. For vectorfield calculations a scatteredInterpolant of scattered data in space is created. The dimensions are quite large but the data remains constant so I wanted to save the object and load it in another session. Saving is quite fast, but loading takes a lot of time (even with '-v6'). So I came to up to try this and this too. Unfortunately scatteredInterpolant does not provide get/set functions, nor can be created by a struct, so serializing the object directly does not work (please have a look at the fex description). So I end up in following code:
clearvars
% saving
maxNum = 173150;
X = randi([1 maxNum],[maxNum 3]);
V = rand(maxNum,1);
Hui = scatteredInterpolant(X,V,'natural');
tic
save('test.mat','Hui','-v6')
toc
tic
Hui_serialized = hlp_serialize(struct(Hui));
save('testSerialized.mat','Hui_serialized','-v6');
toc
clearvars
% loading
tic
load('test.mat')
toc
tic
load('testSerialized.mat')
toc
HuiStruct = hlp_deserialize(Hui_serialized);
Hui = scatteredInterpolant();
for fieldn = fieldnames(HuiStruct)
Hui.(fieldn{1}) = HuiStruct.(fieldn{1});
end
toc
Results in
Elapsed time is 0.016298 seconds.
Warning: Calling STRUCT on an object prevents the object from hiding its implementation details and should thus be
avoided. Use DISP or DISPLAY to see the visible public details of an object. See 'help struct' for more
information.
Elapsed time is 0.030418 seconds.
Elapsed time is 3.033429 seconds.
Elapsed time is 0.007417 seconds.
Elapsed time is 3.078758 seconds.
Of course this is quite suboptimal and equally slow though the loading of the plain data is quite fast (7.4ms!)
So am I right that the real problem with saving/loading class objects is not the file IO itself, but the assignment of the properties?
Can I increase the speed somehow in this case here?
Thank you! Jan
0 Comments
Answers (0)
See Also
Categories
Find more on Workspace Variables and MAT-Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!