MATLAB: Exported timeseries does not look the same as the imported one

interpolationsimulinktimeseriesworkspace

I created a time series in MATLAB using the "timeseries" function. If I import this time series to my model using a "From Workspace" block and then I try to export the same time series using a "To Workspace" block in a "Timeseries" save format, the two curves do not look the same when I plot them. Why is this happening? 

Best Answer

The differences in the two curves are due to the interpolation methods of the time series being different. The "To workspace" block by default uses "zero order hold" interpolation, while the objects created using the "timeseries" function use linear interpolation by default. This can be resolved by setting the interpolation methods to be the same. For example, if "in_ts" represents the time series object created in MATLAB, the following would change the interpolation method to "zoh":
in_ts = setinterpmethod(in_ts,'zoh');