Confusion manipulating timestamp and plotting
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I'm having issues wtih a dataset that was generated by a collaborator and given to us. We have values like the following for time:
0.0517361112797516
0.0520833335031057
0.0524305557264597
0.0527777779498138
0.0531250001731678
0.0534722223965218
0.0538194446198759
0.0541666668432299
0.0545138890665839
0.0548611112899380
0.0552083335132920
I want to be able to plot my data by HH:MM:SS.
I've been able to convert this to a string using datestr(X, 'HH:MM:SS') -- just HH:MM:SS becasue I'm 99% sure the date is completely wrong, but maybe I should keep date because the data spans 2 or 3 days? I am having trouble plotting my results based on hours/minutes/seconds because the value returned is a char / string. I've played around with datnum and others but no luck.
0 comentarios
Respuestas (1)
Jeremy
el 4 de Dic. de 2019
Is each number supposed to represent a datetime as a "datenum" data type?
t = 0.0517361112797516;
d = datetime(t,'ConvertFrom','datenum')
returns
d =
datetime
31-Dec--0001 01:14:30
And then
ds = datestr(d,'HH:MM:SS')
returns
ds =
'01:14:30'
Is this correct?
2 comentarios
Jeremy
el 4 de Dic. de 2019
Editada: Jeremy
el 4 de Dic. de 2019
To add, you could access the hour, minute, and second numbers individually like so:
[hr,s] = strtok(ds,':');
[min,s] = strtok(s,':');
[sec,s] = strtok(s,':');
clear s
hr = str2double(hr);
min = str2double(min);
sec = str2double(sec);
There may be a more efficient way to do this, but this is what came to mind as I was thinking about it.
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!