Split date variable of a table into 3 variables year month and day

5 ビュー (過去 30 日間)
Thomas Vescovini
Thomas Vescovini 2019 年 7 月 16 日
コメント済み: Adam Danz 2019 年 7 月 18 日
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

採用された回答

Adam Danz
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
  2 件のコメント
Thomas Vescovini
Thomas Vescovini 2019 年 7 月 18 日
Thanks, that works perfectly!
Adam Danz
Adam Danz 2019 年 7 月 18 日
Glad I could help!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

製品


リリース

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by