Changing the values of a column in a table.
12 次查看(过去 30 天)
显示 更早的评论
If I have a table ..datafi{1}.. and I want to change the time column, t, from all the times being different to all the times being the same time as the first time listed in the column, how do I do that in Matlab?
0 个评论
回答(1 个)
per isakson
2021-1-28
编辑:per isakson
2021-1-28
This statement does it
tbl.t = tbl.t(ones(height(tbl),1)); % once refered to as "Tony's trick"
Example:
%% Create a sample table
t = datetime('now');
t.Format = t.Format + ".SSSS";
x = (1:5).';
t = sort(t + seconds(5*randn(5, 1)));
tbl = timetable(t,x)
%% Change the time column
tbl.t = tbl.t(ones(height(tbl),1));
tbl
Output
tbl =
5×1 timetable
t x
_________________________ _
28-Jan-2021 11:19:16.7425 1
28-Jan-2021 11:19:23.1767 2
28-Jan-2021 11:19:27.0657 3
28-Jan-2021 11:19:27.1190 4
28-Jan-2021 11:19:38.6666 5
tbl =
5×1 timetable
t x
_________________________ _
28-Jan-2021 11:19:16.7425 1
28-Jan-2021 11:19:16.7425 2
28-Jan-2021 11:19:16.7425 3
28-Jan-2021 11:19:16.7425 4
28-Jan-2021 11:19:16.7425 5
2 个评论
Walter Roberson
2021-1-29
Cast1.Var1 = datetime(Cast1.Var1, 'InputFormat', 'MM/dd/yyyy', 'Format', 'MM-dd-yyyy hh:mm:ss.SSSS') + Cast1.Var2;
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!