フィルターのクリア

Converting a table to a timetable

11 ビュー (過去 30 日間)
Isabelle Museck
Isabelle Museck 2024 年 3 月 15 日
コメント済み: Voss 2024 年 4 月 1 日
Hello there I have a table with time in seconds and acclerometer data in the x,y, and z directions. I am trying to convert my table into a time table to perforom analysis but I get an error saying "table2timetable Input table must contain datetime or duration vector for row times", Any suggestions on hiw to fix this or turn my "Time" variable in my table into a datetime or duration vector?
Thank you so much!

回答 (1 件)

Voss
Voss 2024 年 3 月 15 日
Here's an example:
% a table
T = table([1;2;3],[4;5;6],'VariableNames',{'Time','x'})
T = 3×2 table
Time x ____ _ 1 4 2 5 3 6
% Time column is not duration or datetime
class(T.Time)
ans = 'double'
% try to convert T into a timetable
try
T = table2timetable(T) % error
catch e
disp(sprintf('Error: %s',e.message))
end
Error: Input table must contain datetime or duration vector for row times.
% convert T.Time to durations in seconds
T.Time = seconds(T.Time)
T = 3×2 table
Time x _____ _ 1 sec 4 2 sec 5 3 sec 6
% now Time is duration
class(T.Time)
ans = 'duration'
% and T can be converted into a timetable
T = table2timetable(T)
T = 3×1 timetable
Time x _____ _ 1 sec 4 2 sec 5 3 sec 6
  1 件のコメント
Voss
Voss 2024 年 4 月 1 日
@Isabelle Museck: Did this answer work for you?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by