フィルターのクリア

How do you plot data bi-monthly for the course of a year?

2 ビュー (過去 30 日間)
Dom Smith
Dom Smith 2019 年 4 月 5 日
コメント済み: A. Sawas 2021 年 9 月 28 日
I have a data for a year where I need two plots for each month covering the 1st-15th and 16th-end of month, i.e. bi-monthly plots of this data.
The dataset isn't entirely complete and at some points there is no data for the 1st/15th/16th (as well as other days) of a month.
The data is currently in a timetable with time/date in datetime format 'dd/MM/yyyy HH:mm:ss'.
Is there a way of looping through the data to produce these bi-monthly plots?
My first instinct was to use Timerange, but cannot work out if there is a way to define 'half a month' using this function and plotting every 2 weeks or 15 days soon gets out of phase.
Below is a basic example of what the data looks like (I have added ... just to imply data continues during that time period)
date data
01/01/2018 00:00:00 344.98
01/01/2018 00:30:00 304.13
01/01/2018 01:00:00 355.74
...
13/01/2018 09:30:00 554.13
18/01/2018 10:00:00 344.77
19/01/2018 10:00:00 346.47
27/01/2018 00:30:00 304.13
02/02/2018 01:00:00 357.83
02/02/2018 01:30:00 367.87
...
31/12/2018 22:30:00 634.63
31/12/2018 23:00:00 400.53
31/12/2018 23:30:00 621.43
  1 件のコメント
Dom Smith
Dom Smith 2019 年 4 月 5 日
Perhaps the easiest solution will be to adjust the plot limits
with xlim(datetime(2018,[1 1],[1 15]))
and xlim(datetime(2018,[1 16],[1 30])) and so on (adjusting 30 depending on the number of days in a month).
But I am still not sure how I would write this into a loop.

サインインしてコメントする。

採用された回答

A. Sawas
A. Sawas 2019 年 4 月 6 日
You may use the function datetime to set the lower and upper dates of each bi-monthly period. Then using find to selectively choose the data points between them.
y = 2018;
for m=1:12
t1 = datetime(y,m,01);
t2 = datetime(y,m,16);
i = find(DataT.date => t1 && DataT.date < t2);
% Plot the first half of the month
plot(DataT.date(i), DataT.data(i));
t1 = t2;
t2 = datetime(y,m+1,1); % when m=12 the returned date is the first day of the next year
i = find(DataT.date => t1 && DataT.date < t2);
% Plot the second half of the month
plot(DataT.date(i), DataT.data(i));
end
  3 件のコメント
Carol pacheco
Carol pacheco 2021 年 9 月 28 日
and for cases of wanting to separate a large dataset? where the number of weeks are not exact (23 weeks and 3 days for example ?
A. Sawas
A. Sawas 2021 年 9 月 28 日
You can handle the fractions in a separate block of code

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by