How can I remove the date of a datetime matrix ?

23 次查看(过去 30 天)
Hello,
I am using a datetime matrix in the format which may be 'dd MMM yyyy HH:mm:ss' (first data is '25 Nov 2016 08:00:00' and last one is '25 Nov 2016 19:00:00'. I have some issues when I want to change the x-axis scale of my plots as every data is currently 7.3666e+05 when I use datenum and so I cannot really use it like this.
1) As every data is on the 25/11/16, I would like to use a 'time' matrix instead of a datetime matrix. This may help me with changing the x-axis scale if I can get much smaller numeric values than 7.3666e+05 with datenum.
Am I right ? And if yes, would you know how I could get this 'time' matrix ?
2) If this is not possible or if this cannot help me better, is there a way to change the x-axis scale using directly time with something like the followings ?
xlim(['25 Nov 2016 12:18:00' '25 Nov 2016 12:23:00'])
or
xlim(['12:18:00' '12:23:00'])
Thank you very much for your help.
Arnaud

回答(2 个)

Jan
Jan 2017-1-18
编辑:Jan 2017-1-18
Did you try datetick already? While the xlim limits require the data in the datenum format, the visible tick labels can be set to the date strings easliy with this command.
  3 个评论
Jan
Jan 2017-1-18
I do not understand this sentence:
In that case, I cannot select another range of x-axis if I want
to zoom in (e.g. between 12:10 and 12:20 in plot 1) as all x-axis
values appear the same in plot 2...
In which case? How do you try to select the range? What does "I cannot" mean explicitly? What is "all x-axis value" and they are the "same" as what?
I still do not see, what your problem is. You are right: datetick changes only the tick labels and for setting the limits the command xlim is needed. xlim accepts the numerical date numbers only, and this is exactly what you have to do. So do not use:
xlim(['12:18:00' '12:23:00']) % FAILS
but
xlim([datenum('12:18:00'), datenum('12:23:00')])
Arnaud
Arnaud 2017-1-19
Thank you for your comment.
xlim([datenum('12:18:00'), datenum('12:23:00')])
works but according to the plot I got after this command, it seems to go to the right time but for another day as I got an empty plot with no data. And that day may be 01 Jan 2017 as when I did datenum('12:18:00') on the command window, I got 736696.5125 which is 01-Jan-2017 12:18:00... Would you know why ?
When I use
xlim([datenum('25 nov 2016 12:18:00'), datenum('25 nov 2016 12:23:00')])
it works well so thank you very much for your help !!
But in order to have it simpler, would there be a way without writing '25 nov 2016' as it would always be that same day ?
Thank you, Arnaud

请先登录,再进行评论。


Peter Perkins
Peter Perkins 2017-1-19
It seems like the answer to this question is, "don't plot with datenums." Since R2014a, plotting with datetimes will already leave the date portion of the timestamps out of the tick labels if the data spans only one day.
Plotting datetimes really does work better than using datenum and datetick in most cases, and since R2016b, in all cases. Unless you are using something older than R2014b, or unless you have some good reason not to, use datetime.
  2 个评论
Joshua Remba
Joshua Remba 2018-1-25
Hi Peter, My data spans only 1 day, and the date (month date, year) is written a single time in the bottom right hand corner, below the HH:mm labeled ticks. How can I get rid of that date entirely? Thanks in advance!
Peter Perkins
Peter Perkins 2018-1-26
If that's really what you want, convert the datetimes to durations using the timeofday function.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by