Clear Filters
Clear Filters

symbolic units: sym.saveobj bottleneck

3 views (last 30 days)
Ben Mercer
Ben Mercer on 2 Aug 2021
Hi all,
I'm experiencing a quite significant bottleneck when saving data which includes symbolic measurement units. I'm using symbolic units (e.g. symunit('s')) to represent all of my measurement units - it seemed like a pretty neat feature at face value! Here is some code to demonstrate the issue:
%% Create some dummy data
N = 30;
for n1 = 1:N
myData(n1).x = (0:0.01:5).';
myData(n1).xUnit = symunit('s');
% myData(n1).xUnit = sym('a');
myData(n1).y = sin(2*pi*(1+rand) * myData(n1).x );
myData(n1).yUnit = symunit('V');
% myData(n1).yUnit = sym('b');
%% Save to a file - takes ~20s
profile on
save('myData.mat', 'myData')
profile report
%% Save again to another file - takes ~0.2s
profile on
save('myData2.mat', 'myData')
profile report
So for 30 channels of data with a time and voltage unit expressed as symbolic, saving to a file will take ~20s. If we save the data again to another file, it is much faster at ~0.2s. If we run again from the start (clearing the data in the process), it will take ~20s again. If we replace the symunit() calls with sym() (comment out the symunit calls and uncomment the sym calls), it takes ~0.2s again. So I gather that A) the issue is specific to symbolic units, not symbolics in general, and B) the result of the expensive computation is held persistently and is not re-done on a second call.
I'm running MATLAB R2019B, but can update to a later release if necessary.
I'd be very grateful if anyone can help understand:
  • Is this bottleneck addressed in a later version of Matlab?
  • Are there any possible workarounds?
Many thanks,

Answers (0)




Community Treasure Hunt

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

Start Hunting!