Hi Rub,
First, about your code examples I have some suggestions. I saw you used datenum in your first post. It is good that you replaced datenum with minutes in your second post. It's never a good idea to mix datenum with the newer and preferred datetime. About preallocating a timetable, you can also do it by using timetable preallocation syntax as the following.
ttref = timetable('Size', [length(timeVector), 3], 'VariableTypes', ["double" "double" "double"], 'RowTimes', timeVector);
To answer your question, retime is the right tool for your job. Retime has a syntax TT2 = retime(TT1,NEWTIMES). You can use TTFit{i}=retime(TT{i},timeVector) in your for-loop. Your code will look like the following:
tini = datetime({'01-Apr-2016 00:15:00'});
tfin = datetime({'07-Apr-2017 00:00:00'});
timeVector = [tini:minutes(15):tfin]';
num = length(TT);
TTFit = cell(num,1);
for i=1:num
TTFit{i}=retime(TT{i},timeVector);
end
Furthermore, you can use cellfun to replace your for-loop as
tini = datetime({'01-Apr-2016 00:15:00'});
tfin = datetime({'07-Apr-2017 00:00:00'});
timeVector = [tini:minutes(15):tfin]';
TTFit = cellfun(@(tt)retime(tt, timeVector),TT,'UniformOutput',false);
This runs faster.
I’m interested in why you put your timetables in a cell array, and what you will do with it next. If you are going to concatenate then all to make one timetable, then synchronize is the tool that can help you. Steve suggested calling synchronize using a comma-separated list, which you may not have seen before. Here's what that looks like:
TTFit = synchronize(TT{:},timeVector);
0 Comments
Sign in to comment.