필터 지우기
필터 지우기

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

조회 수: 4 (최근 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 CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by