Confusion manipulating timestamp and plotting
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Jeremy
2019-12-4
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 个评论
Jeremy
2019-12-4
编辑:Jeremy
2019-12-4
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!