Confusion manipulating timestamp and plotting

1 visualizzazione (ultimi 30 giorni)
erkelly il 4 Dic 2019
Commentato: erkelly il 5 Dic 2019
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 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Risposte (1)

Jeremy il 4 Dic 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 CommentiMostra NessunoNascondi Nessuno
Jeremy il 4 Dic 2019
Modificato: Jeremy il 4 Dic 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.
erkelly il 5 Dic 2019
Thank you for your response!
Initially I converted all that data using the datestr, it can be converted directly
d = datestr(d,'mm-dd-yyyy HH:MM:SS');
ds = datetime(v2_1OD(:,1),'convertFrom', 'datenum');
plot(ds, y)
datetick('x', 'HH')
This plots everything and displays hours, but I also want it to plot absolute time rather than hours 0 4 8 12 16 20 24 for 3 separate days.
The strtok command didn't work for me, when I had [h,s]=strtok(d,':')
I did manage to get [h, m, s] = hms(ds) to work. Now I have to figure out the best way to make this absolute values and plot that. I could just convert all values to 'hours' and add them all together, and then add 24 and 48 to the 2nd and third day values. What do you think?

Accedi per commentare.

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by