how do I plot time data (recorded in secods) in hh:mm:ss format?

I have a vector of time stamps - recorded in seconds from the beginning of the record. I want use the time stamps to plot a time series of some other data. I would like to label the x axis in hh:mm:ss format (as opposed to what I have now, where the x axis simply goes from 1:n seconds).

Answers (3)

If you're using MATLAB R2014b or later, one of these is what you're looking for:
1) plot the actual elapsed times as hh:mm:ss -
t = seconds(1:5)
y = 1:5;
plot(t,y,'DurationTickFormat','hh:mm:ss')
or plot realtime as hh:mm:ss -
t0 = datetime(2015,4,24)
t = 1:5;
t = t0 + seconds(t)
plot(t,y,'DatetimeTickFormat','HH:mm:ss')
Hope this helps.
I hope people does not write code that has not been tested! It's a great waste of time to read all the nonsense!

Asked:

on 22 Apr 2015

Answered:

on 24 Jun 2019

Community Treasure Hunt

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

Start Hunting!