MATLAB: Faster way to resample a timeseries

optimizationresampletimeseries

Hello,
I have about one month worth of data in a 1 minute timescale and I have a series of events which I need to resample onto that timescale.
for m=1:length(UniqueEvents)
EventLogical=strcmp(Log.Event, UniqueEvents{m});
%create a time series object for each event
EventSeries=timeseries(EventLogical, datestr(LogBook.EventStartTime));
TimeSeries=resample(EventSeries, datestr(DateTable.TimeStamp), 'zoh');
if m==1
%convert time series into cell array
TableSize=size(getabstime(TimeSeries));
StatusTable=table(zeros(TableSize(1),1));
StatusTable.TimeStamp=datetime(getabstime(TimeSeries));
VarName=strcat('Status_',Var{k});
StatusTable.Var1=[];
end
StatusTable.(VarName)(logical(TimeSeries.Data))=UniqueEvents(m);
end
Using the profiler the vast majority of runtime is a result of the resampling line
TimeSeries=resample(EventSeries, datestr(DateTable.TimeStamp), 'zoh');
Does anyone have any ideas on how to make this faster?

Best Answer

If you're using a release where timetable is available, I recommend storing your data in a timetable and using the retime function.