Create a vector in 15-minute intervals (from 0 am to 24 pm)

6 views (last 30 days)
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?

Answers (1)

Walter Roberson
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')
BT = datetime
12-Jun-2021
T = BT + minutes(sort(1440*rand(1, 500)));
T(1:10)
ans = 1×10 datetime array
12-Jun-2021 00:03:05 12-Jun-2021 00:03:54 12-Jun-2021 00:03:56 12-Jun-2021 00:04:57 12-Jun-2021 00:07:07 12-Jun-2021 00:15:35 12-Jun-2021 00:23:47 12-Jun-2021 00:23:58 12-Jun-2021 00:24:00 12-Jun-2021 00:27:15
V = rand(size(T))
V = 1×500
0.9208 0.8995 0.6975 0.5460 0.2480 0.6074 0.6270 0.5911 0.8992 0.7790 0.8939 0.5660 0.9413 0.7454 0.2384 0.5734 0.3513 0.5612 0.8775 0.7663 0.3734 0.7775 0.0866 0.8703 0.9714 0.2642 0.8139 0.0315 0.7880 0.0938
ticks = BT + minutes(0:15:1440);
Vdis = accumarray(discretize(T(:), ticks), V(:), [length(ticks),1]);
bar(ticks, Vdis)
xticks(ticks)
  4 Comments
Renan Santos
Renan Santos on 19 Jun 2021
Thanks for all, but I'd like to know if there is any way to do it running in MATLAB 2014 R2014a.
In this version doesn't have functions like minutes, datetime, etc.
Walter Roberson
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')

Sign in to comment.

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Products


Release

R2014a

Community Treasure Hunt

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

Start Hunting!