Create a vector in 15-minute intervals (from 0 am to 24 pm)
6 views (last 30 days)
Show older comments
Hi everyone!
I need to create a bar graph with the x axis in 15-minute intervals (from 0 am to 24 pm). Can someone help me to create a vector to do this with HH:MM on the plot?
0 Comments
Answers (1)
Walter Roberson
on 13 Jun 2021
Edited: Walter Roberson
on 13 Jun 2021
Sure, you can xticks() with datetime objects if you have a datetime ruler.
The problem is being able to read it. Every 15 minutes for a day is 96 ticks.
Though for your purposes, perhaps just leaving out the xticks() call on this example would be enough for your purposes.
BT = datetime('yesterday')
T = BT + minutes(sort(1440*rand(1, 500)));
T(1:10)
V = rand(size(T))
ticks = BT + minutes(0:15:1440);
Vdis = accumarray(discretize(T(:), ticks), V(:), [length(ticks),1]);
bar(ticks, Vdis)
xticks(ticks)
4 Comments
Walter Roberson
on 19 Jun 2021
Edited: Walter Roberson
on 19 Jun 2021
as_minutes = 0:15:(24*60)-1;
as_days = as_minutes ./ (24*60);
y = rand(size(as_days)); %something to plot
plot(as_days, y);
datetick('x', 'HH:MM')
See Also
Categories
Find more on Data Distribution Plots 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!