I would like to compute long datetime array in Matlab and hence wishing to preallocate it. Unfortunately when I am using NaT
, I am loosing time component:
>> [datetime(1441411200,'ConvertFrom','posixtime'), datetime(1441411500,'ConvertFrom','posixtime')]
ans =
1×2 datetime array
05-Sep-2015 00:00:00 05-Sep-2015 00:05:00
>> A=NaT(2,1)
A =
2×1 datetime array
NaT
NaT
>> A(1)=datetime(1441411200,'ConvertFrom','posixtime'); A(2)=datetime(1441411500,'ConvertFrom','posixtime');
>> A
A =
2×1 datetime array
05-Sep-2015
05-Sep-2015
How to accomplish?
Matlab version is 2016b
The only problem here is in the Format
property of the array created by NaT
- it gets a different default value. So, you could do:
A = NaT(2, 1);
A.Format = 'dd-MMM-uuuu HH:mm:ss';
A(1) = datetime()
which results in
A =
2×1 datetime array
30-Apr-2018 10:34:47
NaT
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.