Show time in x axis with increments of 10minutes
24 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mathan
am 4 Apr. 2022
Kommentiert: Mathan
am 5 Apr. 2022
Hello,
I was wondering whether it is possible to plot a graph with time on x axis that varies with 10 minute (or 15 minute or 20 minute) increment (i.e. as per our choice). For instance, I have two times:
t_start = 10-Jun-2015 03:30:00 (which is the start time)
t_end = 10-Jun-2015 05:00:00 (is the end time)
How can I have a plot with x axis containing ticks such as 03:30, 03:40, 03:50........04:40, 04:50, 05:00.
I tried:
xtks = linspace(t_start, t_end, 20);
xticks(xtks);
xlim([t_start, t_end]);
datetick('x','HH:MM','keepticks', 'keeplimits');
But this just produces an x axis with 20 equally divided ticks (not increments as shown above). I tried with 10, 15, etc instead of 20 for xtks but still it does'not come out as expected.
Any help is appreciated.
Thanks
2 Kommentare
Walter Roberson
am 4 Apr. 2022
Is your t_start and t_end in the form of serial date numbers or in the form of datetime() objects? datetick() is only used for serial date numbers.
Akzeptierte Antwort
Walter Roberson
am 4 Apr. 2022
t_start = datetime('10-Jun-2015 03:30:00'); %(which is the start time)
t_end = datetime('10-Jun-2015 05:00:00'); %(is the end time)
t = t_start : minutes(1) : t_end;
ndata = length(t);
data = rand(1, ndata);
plot(t, data);
xticks(t_start:minutes(15):t_end);
4 Kommentare
Walter Roberson
am 4 Apr. 2022
For serial date numbers,
incr = increment_in_minutes/(24*60)
xticks(t_start:incr:t_end)
and then datetick() like you show
Ideally in both cases more work should be done to round t_start to the start of the desired period, so you do not have the risk of ticks at (say) 3:17, 3:27, 3:37 and so on if the data happened to end like that. dateshift() can help for that.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Dates and Time finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!