필터 지우기
필터 지우기

table2timetable with Time as double

조회 수: 21 (최근 30일)
John Math
John Math 2024년 5월 6일
이동: Steven Lord 2024년 5월 6일
Hello,
I have the following table :
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

답변 (2개)

Stephen23
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)
  댓글 수: 1
John Math
John Math 2024년 5월 6일
이동: Steven Lord 2024년 5월 6일
thanks, I tried it last night without sucess, worked like a charm today. probably I was the source of the problem.

댓글을 달려면 로그인하십시오.


Star Strider
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)
TTx = 30x1 timetable
Time Position _______ ________ 00.0292 0.10935 00.0516 0.38739 00.0741 0.44271 00.1055 0.68116 00.1132 0.60149 00.1546 0.90425 00.1642 0.86509 00.2479 0.97991 00.2521 0.98361 00.2886 1.1611 00.3057 0.75028 00.3511 0.82205 00.3683 0.70712 00.3853 0.6059 00.4340 0.40684 00.5415 -0.17432
TTy = resample(TTx)
TTy = 30x1 timetable
Time Position _______ _________ 00.0292 0.10935 00.0623 0.41367 00.0954 0.60453 00.1285 0.71319 00.1616 0.87583 00.1946 0.90688 00.2277 0.95226 00.2608 1.0258 00.2939 1.0342 00.3270 0.78389 00.3600 0.76228 00.3931 0.57409 00.4262 0.43887 00.4593 0.27028 00.4924 0.091338 00.5254 -0.087604
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')
.

카테고리

Help CenterFile Exchange에서 Timetables에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by