How to convert datenum to datetime in a MATLAB Table

24 ビュー (過去 30 日間)
Shambhavi Adhikari
Shambhavi Adhikari 2020 年 1 月 20 日
回答済み: Andrei Bobrov 2020 年 1 月 20 日
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.

回答 (2 件)

Bhaskar R
Bhaskar R 2020 年 1 月 20 日
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 2020 年 1 月 20 日
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]);

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by