converting seconds to date in a plot

8 次查看(过去 30 天)
Hello. Im trying to plot a 'Huge' variable which will contains more than 1,000,000 rows. Initially, X axis is formatted as seconds. I would like to set(define) a start date/time/seconds, like 8/14/2017 10:03:44.22334 and plot it on the graph as the time-date-hours-mins-seconds format. I took a look at related functions but I could not really get it. Can anyone help with it? Thank you!

采纳的回答

mizuki
mizuki 2017-8-15
If you write a question with your sample code, it is easy for us to find out your problem as well as you would get more suitable answers.
DATETICK allows you to change the ticklabel of the figure with datetime format.
timestr = datetime('08/14/2017 10:03:44.22334', 'InputFormat', 'MM/dd/yyyy HH:mm:ss.SSSSS')+ seconds(0:1:10)
h = plot(timestr, rand(1,11), 'o');
datetick('x', 'DD-HH-mm-ss')

更多回答(1 个)

Peter Perkins
Peter Perkins 2017-8-15
The answer depends on what version of MATLAB you are using. Using datetick with a plot of datetimes probably works prior to R2016b, but going forward it's not what you'd want to do. In R2016b or later, do this:
>> t = seconds(1000*sort(rand(100,1)));
>> x = 1:100;
>> plot(t,x) % plot data vs. time in seconds
>> d = datetime(2017,8,14,10,3,44,223.34,'Format','MM/dd/yyyy HH:mm:ss.SSSSSS') + t;
>> plot(d,x) % plot data vs. absolute time
If you don't like the date/time format that plot chooses automatically, you can set it explicitly:
>> ax = gca; ax.XAxis.TickLabelFormat = 'dd-HH-mm-ss'

类别

Help CenterFile Exchange 中查找有关 Grid Lines, Tick Values, and Labels 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by