How can I do a datetime vector?
Mostrar comentarios más antiguos
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 comentario
dpb
el 25 de Mzo. de 2019
>> 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...
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Dates and Time en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!