table2timetable with Time as double
21 次查看(过去 30 天)
显示 更早的评论
Hello,
I have the following table :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1687246/image.png)
The data come from a CAN trace, hence the varialbe time step.
My final goal is to do some analysis on the data.
My understanding is that it would be easier with a timetable and a resampling.
But I fail to convert this to a timetable :
my_timetable=table2timetable(my_traces(4).ewellix_num_data.fbk.ID04);
Error using table2timetable (line 59)
Input table must contain datetime or duration vector for row times.
my_timetable=table2timetable(my_traces(4).ewellix_num_data.fbk.ID04,"RowTimes","Time");
Error using table2timetable (line 135)
Row times must be datetime or duration vector.
I have the feeling that the type of Time variable is not correct but I had no luck trying to convert it.
Thanks
0 个评论
回答(2 个)
Stephen23
2024-5-6
移动:Steven Lord
2024-5-6
You need to convert the TIME column/variable to e.g. a DURATION object.
For example, if the time is given in seconds then you could use the SECONDS function:
For example, where T is your table:
T.Time = seconds(T.Time)
Star Strider
2024-5-6
The resample function works with timetable arrays. See Resample Nonuniformly Sampled Data in Timetable for an example.
Timesec = sort(rand(30,1));
Time = datetime([zeros(numel(Timesec),5) Timesec], 'Format','ss.SSSS');
Position = sin(2*pi*Timesec) + randn(size(Timesec))/10;
TTx = timetable(Time,Position)
TTy = resample(TTx)
figure
plot(TTx.Time, TTx.Position, 'o-', 'DisplayName','Original Data')
hold on
plot(TTy.Time, TTy.Position, 's-', 'DisplayName','Resampled Data')
hold off
grid
xlabel('Time')
ylabel('Position')
legend('Location','best')
.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Timetables 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!