Azzera filtri
Azzera filtri

How to convert datenum to datetime in a MATLAB Table

21 visualizzazioni (ultimi 30 giorni)
Hello, I have a table with list Ids in numbers and corresponding datenum in which these Ids were occured. Can you please help me to convert these datenum to dates?
The table is like this:
ID_1 Dates_1 ID_2 Dates_2
2 737735.191331019 6 737735.182129630
3 737735.182013889 7 737735.141481482
I tried this:
for counter= 1:(size(table,1))
if mod(counter,2)==0
table{:,col_name}=datetime(table{:,col_name},'ConvertFrom', 'datenum');
And i got error like this:
The following error occurred converting from datetime to double:
Undefined function 'double' for input arguments of type 'datetime'. To convert from datetimes to numeric, first subtract off a datetime origin, then convert to numeric using the SECONDS, MINUTES, HOURS, DAYS, or YEARS functions.

Risposte (2)

Bhaskar R
Bhaskar R il 20 Gen 2020
Suppose T is your table variable
T.Dates_1 = datetime(T.Dates_1, 'ConvertFrom', 'datenum');
T.Dates_2 = datetime(T.Dates_2, 'ConvertFrom', 'datenum');

Andrei Bobrov
Andrei Bobrov il 20 Gen 2020
a=[2 737735.191331019 6 737735.182129630
3 737735.182013889 7 737735.141481482];
T = array2table(a,'V',{'ID_1','Dates_1','ID_2','Dates_2'});
T = [T,varfun(@(x)datetime(x,'ConvertFrom','datenum'),T,'InputVariable',[2,4])];
Tout = T(:,[1,5,3,6]);


Scopri di più su Dates and Time in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by