How to plot a specific period of data
Show older comments
Hi. I am a student. I am trying to plot a graph which will show only a month out of a year data.
What I have: daily data from 01.01.19 to 31.12.2019 data_year(8760x1) and relative time step t(8760x1) -converted from dates and times.
I want to show a graph for September only.
How to do it?
What I did:
startDate = datenum('01-Sep-2019','dd-mmm-yyyy');
endDate = datenum('30-Sep-2019', 'dd-mmm-yyyy');
tma=datenum([2019 9 1 0 0 0]) + [0:1/24:30]
tt = (tma>=startDate & tma<=endDate);
figure
plot(tma(tt),data_year(tt))
datetick('x','dd mmm yyyy','KeepTicks');
set(gca,'XTickLabelRotation',30);
It works but I do not think it is correct.
Thank you in advance
1 Comment
Mathieu NOE
on 4 Feb 2021
isbetween
Determine elements within date and time interval
Syntax
Description
tf = isbetween(t,tlower,tupper) returns an array containing logical 1 (true) where the corresponding element of t is a datetime or duration value that lies within the closed interval specified by the corresponding elements of tlower and tupper. The output tf indicates which elements of t satisfy:
tlower <= t <= tupper
The sizes of t, tlower, and tupper must be the same or be compatible. If the sizes of the input arrays are compatible, then the arrays implicitly expand to match each other. For example, if one of t, tlower, or tupper is a scalar, then the scalar is compared to each element of the other arrays. Also, vectors with different orientations (row vectors and column vectors) implicitly expand to form a matrix.
Answers (0)
Categories
Find more on Line 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!