How can I do a datetime vector?
이전 댓글 표시
Hello, how can I do a datime vector. I have a vector whose name is T where I have date and time in this format : '03/19/2019 16:36:41', I want only the time so I write:
for(i=2:n)%I don't want the first row so I start from 2
a=T{i};
x(i,:)=a(11:end);
...
then I want to put every element of x (x is a matrix 1159x9) into a datetime vector so I do:
for (j=1:n-1)
H{j}=datetime(x(i,:),'Format','HH:mm:ss');
end
end
Matlab doesn't show any error but if I try to view H{34}, for example, it doesn't show me anything.
댓글 수: 1
dpb
2019년 3월 25일
>> t= '03/19/2019 16:36:41'; % your sample input form...
>> datetime(t(11:end))
ans =
datetime
25-Mar-2019 16:36:41
>>
shows that with datetime you simply cannot have just a time; there's always an implied date if not a specific one.
You can return arrays of the time components from a datetime array but you can't create the array in the beginning without a date being associated with the time. I, personally, tend to think this is an undesireable limitation as well, but it is what it is and I don't see TMW changing it.
Time-only vectors can only be some form of a duration; either calendar or absolute.
Your code not returning anything is an error don't see a cause for otomh, but you don't need a loop as datetime is vectorized for cell array of strings but you can't actually do what you're trying to do anyways...
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!