how to create array datetime
1 次查看(过去 30 天)
显示 更早的评论
i want datetime in this format :
01/02/2008 501 (day/month/years and time)
i try it :
bbb=datetime(bb,"InputFormat", "dd/MM/yyyy");
but i get error format
1 个评论
采纳的回答
Voss
2024-5-13
load matlab_A
A
hh = floor(A(:,4)/100);
mm = mod(A(:,4),100);
ss = zeros(size(A,1),1);
B = [A(:,[1 2 3]) hh mm ss];
D = datetime(B,'Format','dd/MM/yyyy Hmm')
6 个评论
Stephen23
2024-5-20
Note that by supplying the units separately you could minimize the seconds to one single 0 and write less code:
A = load('matlab_A.mat').A
hh = fix(A(:,4)/100);
mm = mod(A(:,4),100);
D = datetime(A(:,1),A(:,2),A(:,3),hh,mm,0, 'Format','dd/MM/yyyy Hmm')
更多回答(2 个)
Cris LaPierre
2024-5-13
编辑:Cris LaPierre
2024-5-13
You have the correct function, just the wrong syntax. The biggest issue I see with the conversion is that your time appears to be in millitary format, or HHmm.
I therefore think the simplest approach is to convert your array into a string arrary and then use the syntax t = datetime(DateStrings)
load matlab_A.mat
A
% Capture the time
D = datetime(num2str(A),'InputFormat',"yyyy M d Hmm",'Format',"dd/MM/yyyy Hmm")
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio and Video Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!