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:
N = 30;
for n1 = 1:N
myData(n1).x = (0:0.01:5).';
myData(n1).xUnit = symunit('s');
myData(n1).y = sin(2*pi*(1+rand) * myData(n1).x );
myData(n1).yUnit = symunit('V');
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?