How can I remove the date of a datetime matrix ?
23 views (last 30 days)
Show older comments
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
0 Comments
Answers (2)
Jan
on 18 Jan 2017
Edited: Jan
on 18 Jan 2017
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 Comments
Jan
on 18 Jan 2017
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')])
Peter Perkins
on 19 Jan 2017
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 Comments
Joshua Remba
on 25 Jan 2018
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
on 26 Jan 2018
If that's really what you want, convert the datetimes to durations using the timeofday function.
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
