Split date variable of a table into 3 variables year month and day
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Thomas Vescovini
el 16 de Jul. de 2019
Comentada: Adam Danz
el 18 de Jul. de 2019
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 comentarios
Respuesta aceptada
Adam Danz
el 17 de Jul. de 2019
"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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!