How to convert datenum to datetime in a MATLAB Table

20 Ansichten (letzte 30 Tage)
Shambhavi Adhikari
Shambhavi Adhikari am 20 Jan. 2020
Beantwortet: Andrei Bobrov am 20 Jan. 2020
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
col_name=table.Properties.VariableNames{counter};
table{:,col_name}=datetime(table{:,col_name},'ConvertFrom', 'datenum');
end
end
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.

Antworten (2)

Bhaskar R
Bhaskar R am 20 Jan. 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 am 20 Jan. 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]);

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by