Use retime() to resample to fractional seconds?
3 次查看(过去 30 天)
显示 更早的评论
Timetables look to be very flexible, but I have data timed to msecs and would like to resample to some higher fractional second rate, such as 0.1 sec. Is there any way to use retime to do that? It appears retime may be limited to 1 second in resolution.
0 个评论
采纳的回答
Steven Lord
2018-2-15
The smallest value allowed for the newTimeStep input argument describe in the documentation for retime is 'secondly', but you can create a vector of new times with whatever spacing you want and use that as the newTimes input argument for retime.
% Get a starting time
N = datetime('now');
N.Format = 'HH:mm:ss.SSSS';
% Make the timetable spanning 1 second with some arbitrary data to retime
tt = timetable(N+seconds([0; 1; 3; 6; 10]./10), [0; 1; 10; 100; 1000])
% New time vector with spacing (timing?) of 0.1 second
tv = (N:seconds(0.1):N+seconds(1)).'
% retime it
newtt = retime(tt, tv, 'linear')
The value of Var1 for the third entry in tv, N+seconds(0.2), should be 5.5 which is halfway between the value of 1 for N+seconds(0.1) and the value of 10 for N+seconds(0.3).
更多回答(1 个)
Peter Perkins
2018-2-17
If you are working in sub-second resolutions, probably best to use the milliseconds function, rather than seconds, for anything involving fractional seconds. By the time you type 0.1, you're into floating point round-off. That may or may not matter; in many cases it won't. And of course this really only pushes the issue down into sub-MILLIsecond resolutions.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Identification 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!