MATLAB Answers

# How to pick the right month?

1 view (last 30 days)
gjashta on 30 Apr 2019
Commented: gjashta on 5 May 2019
The data file covered 13 years from 2003-2016.
But in the data there is no date just the values of prices and demand.
So, can you help me to write a simple code to pick the date,
for example the data of march for all the years?? Then how to calculate the mean and the std for each month?
##### 2 CommentsShowHide 1 older comment
gjashta on 1 May 2019
Sorry for my mistake!

Sign in to comment.

### Accepted Answer

Walter Roberson on 30 Apr 2019
Price = Data1(:,1);
Demand = Data1(:,2);
tv = (datetime([2003,1,1]):datetime([2015,12,31])).';
[Y,M,D] = ymd(tv);
DT = timetable(Price, Demand, Y, M, D, 'RowTimes', tv);
Now you can do tests such as
MarchData = DT(DT.M==3,:);
and you can also use timerange() selectors, https://www.mathworks.com/help/matlab/ref/timerange.html
and you can also do calculations such as
retime(DT, 'monthly', 'sum')
##### 4 CommentsShowHide 3 older comments
gjashta on 5 May 2019
How can I substract the mean of march for each year from the daily demand of march? Two vectors with defferent length.

Sign in to comment.

### Community Treasure Hunt

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

Start Hunting!