Split date variable of a table into 3 variables year month and day
4 次查看(过去 30 天)
显示 更早的评论
Hi, I have table with 3 variables (date, latitude, longitude) where the first variable is the date (dd/mm/yyyy) and I want the create a table with 5 variables with the following schema :
year month day latitude longitude
2002 01 01 xxx xxx
I didn't find out how to use datenum and datevec the right way...
Thank you,
TV
0 个评论
采纳的回答
Adam Danz
2019-7-17
"I have table with 3 variables (date, latitude, longitude) where the first variable is the date (dd/mm/yyyy)"
% Create example table
T = table(datestr(round(now()-(0:5))','dd/mm/yyyy'),rand(6,1)*100, rand(6,1)*100, ...
'VariableName', {'date','latitude','longitude'});
"I want the create a table with 5 variables with the following schema..."
% parse dates
[y,m,d] = datevec(T.date, 'dd/mm/yyyy');
Tdate = table(y,m,d,'VariableName',{'year','month','day'});
% Create new table
Tnew = [Tdate,T(:,{'latitude','longitude'})];
Result
Tnew =
6×5 table
year month day latitude longitude
____ _____ ___ ________ _________
2019 7 18 84.565 40.058
2019 7 17 44.594 91.371
2019 7 16 54.392 67.381
2019 7 15 75.07 39.048
2019 7 14 89.192 41.376
2019 7 13 58.357 70.361
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!