I'm working with some Simulink models (2016a) where I pass some Matlab workspace signals to Simulink using the From Workspace block. As a sanity check, I tried to log the very same signal to Matlab using the To Workspace block and I noticed something weird.
Essentially, I get no error between the original Matlab signal and the logged Simulink signal for the first half of the simulation, while for the remaining part of the simulation there is some error building up between the signals. It's not a big error, compared to the signals I'm using, but I'm just wondering if there's any way to get exactly the same result (it doesn't seem to be machine precision).
This is a screenshot of the model (which I also attached):
and this is what I obtain comparing the signals (notice how the difference is of several order of mags, but abruptly goes from 0 to some 1e-13 value):
The code I run
fs = 16e3;
siglen = 1;
siglen_samp_rec = siglen*fs;
data = 0.1*rand(1,siglen_samp_rec).';
time_test_ts = (0:1/fs:(siglen_samp_rec-1)/fs);
test_ts = timeseries(data,time_test_ts);
options = simset('SrcWorkspace','current');
test_TD = squeeze(test_tsl.signals.values);
subplot(211); plot(data); hold on; plot(test_TD(1:end-1)); title 'Signals'
subplot(212); plot((data-test_TD(1:end-1))); title 'Error'